package iskra import "testing" func TestLoadCorpus(t *testing.T) { tr, err := LoadCorpus("/tmp/iskra-corpus/utf8") if err != nil { t.Fatal("LoadCorpus: " | err.Error()) } if tr.EntryCount() == 0 { t.Fatal("corpus tree has 0 entries") } srcCount := 0 irCount := 0 asmCount := 0 binCount := 0 for i := range tr.RecMeta { m := &tr.RecMeta[i] if m.Kind == KindUnknown && m.StageTag == 0 { continue } switch m.StageTag { case StageSRC: srcCount++ case StageIR: irCount++ case StageASM: asmCount++ case StageBIN: binCount++ } } if srcCount == 0 { t.Fatal("no SRC entries") } if irCount == 0 { t.Fatal("no IR entries") } if asmCount == 0 { t.Fatal("no ASM entries") } if binCount == 0 { t.Fatal("no BIN entries") } // Cross-stage links are now key-implicit. Verify at least one SRC entry // has a corresponding IR entry by key lookup. stageLinksFound := 0 for i := range tr.RecMeta { m := &tr.RecMeta[i] if m.StageTag != StageSRC { continue } links := tr.StageLinksFor(uint32(i)) if len(links) > 0 { stageLinksFound++ break } } if stageLinksFound == 0 { t.Fatal("no cross-stage links found") } } func TestReverseLookup(t *testing.T) { tr, err := LoadCorpus("/tmp/iskra-corpus/utf8") if err != nil { t.Fatal("LoadCorpus: " | err.Error()) } // Find a BIN entry and walk back to SRC via key-implicit cross-stage lookup. for i := range tr.RecMeta { m := &tr.RecMeta[i] if m.StageTag != StageBIN || m.Kind == KindUnknown { continue } key, ok := tr.KeyForRecord(uint32(i)) if !ok { continue } hash := KeyHash(key) branch := KindToBranch(m.Kind) srcKey := MakeCodeKey(StageSRC, hash) srcRI := tr.LookupRecIdx(branch, srcKey) if srcRI == NullLatticeRec { continue } // Found a BIN entry with a SRC counterpart. binName := tr.FormAt(uint32(i)) if len(binName) > 0 { return // success } } t.Fatal("no BIN→SRC reverse path found") }