Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add testgen to generate test cases #1801

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7de8112
testgen: prepare for test generation
mewmew Oct 12, 2019
cb22e77
testgen: rename MakefileVC to Makefile
mewmew Oct 12, 2019
3976dfc
testgen: add testgen build to Makefile
mewmew Oct 12, 2019
3599bd3
testgen: add test case for drlg_l1
mewmew Oct 12, 2019
2e59003
testgen: dump test data for dungeon pieces, arches and transparency o…
mewmew Oct 12, 2019
26d2add
testgen: add table for test cases
mewmew Oct 12, 2019
dde50c3
testgen: add more test cases for drlg_l1
mewmew Oct 12, 2019
5d0e48d
move Makefile back to MakefileVC
mewmew Oct 12, 2019
3545d9d
move MakefileGCC back to Makefile
mewmew Oct 12, 2019
8bf78a9
testgen: add TESTGEN define to use WinMain of SourceT/main.cpp
mewmew Oct 12, 2019
e41b800
testgen: use TESTGEN to handle testgen.exe specific changes
mewmew Oct 12, 2019
8f30306
clean testgen objects
mewmew Oct 12, 2019
55ecd40
testgen: add test case for Skeleton King's Lair
mewmew Mar 23, 2020
3eeba0b
testgen: fix build after rebasing on master
mewmew Mar 23, 2020
e2e688e
testgen: set setlvlnum to zero when not in a set level
mewmew Mar 23, 2020
cbe5638
testgen: add broken seed 7281
mewmew Mar 23, 2020
adcdb45
cmd/viewdun: add viewdun tool to convert TILES.BIN to DUN
mewmew Mar 23, 2020
4a463fc
d1/l1: add test case for entrance to Skeleton King's Lair
mewmew Mar 25, 2020
02c214f
testgen: replace dump_dun.sh script with equivalent Makefile
mewmew Mar 25, 2020
64425bc
testgen: invoke LoadSetMap for instead CreateL5Dungeon of set levels
mewmew Mar 25, 2020
5ad5ee8
testgen: add more broken seeds
mewmew Mar 25, 2020
4ee568d
testgen: format source code
mewmew Mar 25, 2020
bad2361
testdata: add 1666 seed
mewmew Mar 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# macOS
.DS_Store

# Error files.
*.ERR

# CodeLite
.CodeLite
*.project
Expand All @@ -15,6 +18,12 @@
devilution-comparer
comparer-config.toml

# MPQ archives
*.mpq

# Generated test data.
testdata

# ELF object file.
*.o

Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,28 @@ LDFLAGS=-L./ -static-libgcc -mwindows

all: devilution.exe

testgen: CXXFLAGS += -DTESTGEN -I./SourceT -Wno-narrowing
testgen: testgen.exe

debug: CXXFLAGS += -D_DEBUG
debug: CPPFLAGS += -D_DEBUG
debug: devilution.exe

DIABLO_SRC=$(sort $(filter-out Source/_asm.cpp Source/_render.cpp, $(wildcard Source/*.cpp)))
OBJS=$(DIABLO_SRC:.cpp=.o)

TESTGEN_SRC=SourceT/testgen.cpp
TESTGEN_OBJS=$(TESTGEN_SRC:.cpp=.o)

PKWARE_SRC=$(wildcard 3rdParty/PKWare/*.cpp)
PKWARE_OBJS=$(PKWARE_SRC:.cpp=.o)

devilution.exe: $(OBJS) $(PKWARE_OBJS) diabres.o diabloui.lib storm.lib
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

testgen.exe: $(OBJS) $(TESTGEN_OBJS) $(PKWARE_OBJS) diabres.o diabloui.lib storm.lib
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

diabres.o: Diablo.rc
$(WINDRES) $< $@

Expand All @@ -50,6 +59,6 @@ storm.dll:
# $(error Please copy storm.dll (version 1.09[b]) here)

clean:
@$(RM) -v $(OBJS) $(OBJS:.o=.d) $(PKWARE_OBJS) $(PKWARE_OBJS:.o=d) diabres.o storm.lib diabloui.lib devilution.exe
@$(RM) -v $(OBJS) $(TESTGEN_OBJS) $(OBJS:.o=.d) $(PKWARE_OBJS) $(PKWARE_OBJS:.o=d) diabres.o storm.lib diabloui.lib devilution.exe

.PHONY: clean all
29 changes: 29 additions & 0 deletions MakefileTestgen
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#TILES_BIN_NAME=dlvl=3,quest_id=12,seed=123,setlvl=0_tiles.bin
#TILES_BIN_PATH=testdata/${TILES_BIN_NAME}
#DUN_NAME=${TILES_BIN_NAME/.bin/.bin.dun}
#DUN_FROM=testdata/${DUN_NAME}
#DUN_TO=testdata/levels/l1data/${DUN_NAME}

TILES_BIN=$(wildcard testdata/*_tiles.bin)
DUN_FROM=$(TILES_BIN:.bin=.bin.dun)
DUN_TO=$(subst testdata/,testdata/levels/l1data/,$(DUN_FROM))

all: $(DUN_TO) _dump_/_tilesets_

testdata/%.bin.dun: testdata/%.bin
./cmd/viewdun/viewdun $<

testdata/levels/l1data/%.bin.dun: testdata/%.bin.dun
mkdir -p testdata/levels/l1data
mv $< $@
dun_dump -tilesets=false $@

_dump_/_tilesets_:
@echo "This step creates the tilesets and parses a dummy DUN file. It is expected to fail as the dummy file does not exist."
dun_dump -tilesets=true dummy

clean:
$(RM) -v $(DUN_TO)
$(RM) -v $(DUN_FROM)
$(RM) -r -v _dump_/_tilesets_
$(RM) -r -v _dump_/_dungeons_
11 changes: 10 additions & 1 deletion MakefileVC
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ endif

all: Diablo.exe

testgen: CFLAGS += /D "TESTGEN" /I ./Source /I ./SourceT
testgen: testgen.exe

debug: CFLAGS += /D "_DEBUG"
debug: Diablo.exe

Expand All @@ -62,9 +65,15 @@ DIABLO_SRC=$(sort $(filter-out Source/_asm.cpp Source/_render.cpp Source/render.
DIABLO_SRC += Source/render.cpp
OBJS=$(DIABLO_SRC:.cpp=.obj)

TESTGEN_SRC=$(sort $(wildcard SourceT/*.cpp))
TESTGEN_OBJS=$(TESTGEN_SRC:.cpp=.obj)

Diablo.exe: main_files diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib 3rdParty/PKWare/pkware.lib
$(VC_LINK) /OUT:$@ $(LINKFLAGS) $(OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib 3rdParty/PKWare/pkware.lib

testgen.exe: main_files $(TESTGEN_OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib 3rdParty/PKWare/pkware.lib
$(VC_LINK) /OUT:$@ $(LINKFLAGS) $(OBJS) $(TESTGEN_OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib 3rdParty/PKWare/pkware.lib

DiabloUI/diabloui.lib:
make -C DiabloUI

Expand All @@ -85,6 +94,6 @@ diablo.res: Diablo.rc
$(RC) /i $(VC6_INC_DIR) /l 0x409 /fo $@ $<

clean:
@$(RM) -v $(OBJS) vc60.idb vc60.pdb Diablo.pdb Diablo.pch
@$(RM) -v $(OBJS) $(TESTGEN_OBJS) vc60.idb vc60.pdb Diablo.pdb Diablo.pch

.PHONY: clean all
2 changes: 2 additions & 0 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ BOOL diablo_get_not_running()
* @param lpCmdLine The command line for the application
* @param nCmdShow Initial window state
*/
#ifndef TESTGEN
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HINSTANCE hInst;
Expand Down Expand Up @@ -329,6 +330,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi

return FALSE;
}
#endif

void diablo_parse_flags(char *args)
{
Expand Down
9 changes: 9 additions & 0 deletions SourceT/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "testgen.h"

#include "all.h"

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
ghInst = hInstance;
testgen();
return 0;
}
246 changes: 246 additions & 0 deletions SourceT/testgen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
#include <stdio.h>
#include <stdlib.h>

#include "all.h"

void write_file(char *path, void *buf, int size);

// drlg_l1.cpp

#define SL_NONE 0
#define Q_INVALID -1

void gen_drlg_l1_tests(void) {
printf("gen_drlg_l1_tests\n");

typedef struct {
// meta.
char *dungeon_name;
// pre.
BYTE dlvl;
BYTE dtype;
BYTE quest_id;
DWORD seed;
BYTE setlvl;
} Golden;

// Golden test cases.
Golden golden[] = {
{
"Cathedral", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
123, // seed
SL_NONE, // setlvl
},
{
"Cathedral (fix corners)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
35, // seed
SL_NONE, // setlvl
},
{
"The Butcher", // dungeon_name
questlist[Q_BUTCHER]._qdlvl, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_BUTCHER, // quest_id
123, // seed
SL_NONE, // setlvl
},
{
"Poisoned Water Supply", // dungeon_name
questlist[Q_PWATER]._qdlvl, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_PWATER, // quest_id
123, // seed
SL_NONE, // setlvl
},
{
"Ogden's Sign", // dungeon_name
questlist[Q_LTBANNER]._qdlvl, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_LTBANNER, // quest_id
123, // seed
SL_NONE, // setlvl
},
{
"Skeleton King's Lair (entrance)", // dungeon_name
questlist[Q_SKELKING]._qdlvl, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_SKELKING, // quest_id
123, // seed
SL_NONE, // setlvl
},
{
"Skeleton King's Lair", // dungeon_name
questlist[Q_SKELKING]._qdlvl, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_SKELKING, // quest_id
123, // seed
SL_SKELKING, // setlvl
},
// Broken seeds.
{
"Cathedral (broken seed)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
2588, // seed
SL_NONE, // setlvl
},
{
"Cathedral (broken seed)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
4743, // seed
SL_NONE, // setlvl
},
{
"Cathedral (broken seed)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
7281, // seed
SL_NONE, // setlvl
},
{
"Cathedral (broken seed)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
9345, // seed
SL_NONE, // setlvl
},
{
"Cathedral (broken seed)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
15236, // seed
SL_NONE, // setlvl
},
// extra
{
"Cathedral (666)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
1666, // seed
SL_NONE, // setlvl
},
};

// extra.
int in_entry = 0;
BYTE in_max_players = 1; // single

// Load MPQ archives.
init_archives();

// Load level graphics.
//diablo.LoadLevelGraphics();
leveltype = DTYPE_CATHEDRAL;
LoadLvlGFX(); // TODO: only load level graphics once per dtype.

for (int i = 0; i < sizeof(golden) / sizeof(Golden); i++) {
Golden g = golden[i];

// Reset globals (not needed).
memset(pdungeon, 0, sizeof(pdungeon));
memset(dungeon, 0, sizeof(dungeon));
memset(dPiece, 0, sizeof(dPiece));
memset(dSpecial, 0, sizeof(dSpecial));
memset(dTransVal, 0, sizeof(dTransVal));

//*gendung.DType = g.dtype;
leveltype = g.dtype;

// Establish pre-conditions.
//*gendung.DLvl = g.dlvl;
currlevel = g.dlvl;
//*multi.MaxPlayers = 1;
gbMaxPlayers = in_max_players;
//for i := range quests.Quests {
// quests.Quests[i].ID = quests.QuestID(i);
// quests.Quests[i].Active = false;
//}
for (int quest_id = 0; quest_id < MAXQUESTS; quest_id++) {
quests[quest_id]._qtype = quest_id;
quests[quest_id]._qactive = false;
}

//*gendung.IsQuestLevel = false;
if (g.setlvl != SL_NONE) {
setlevel = true;
setlvlnum = g.setlvl;
} else {
setlevel = false;
setlvlnum = SL_NONE;
}

//if g.questID != quests.Invalid {
// quests.Quests[g.questID].Active = true;
// quests.Quests[g.questID].DLvl = g.dlvl;
//}
if (g.quest_id != Q_INVALID) {
quests[g.quest_id]._qlevel = g.dlvl;
quests[g.quest_id]._qactive = true;
}

// Generate dungeon based on the given seed.
//l1.CreateDungeon(g.seed, 0);

if (g.setlvl != SL_NONE) {
LoadSetMap();
} else {
CreateL5Dungeon(g.seed, in_entry);
}

// Dump pre-dungeon tiles.
char output_path[MAX_PATH];
//sprintf(output_path, "testdata/pre-tiles_%d.bin", g.seed);
//write_file(output_path, pdungeon, sizeof(pdungeon));

// Dump tiles.
sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_tiles.bin", g.dlvl, g.quest_id, g.seed, g.setlvl);
printf("creating '%s'\n", output_path);
write_file(output_path, dungeon, sizeof(dungeon));

// Dungeon dungeon pieces.
sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_dpieces.bin", g.dlvl, g.quest_id, g.seed, g.setlvl);
printf("creating '%s'\n", output_path);
write_file(output_path, dPiece, sizeof(dPiece));

// Dungeon arches.
sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_arches.bin", g.dlvl, g.quest_id, g.seed, g.setlvl);
printf("creating '%s'\n", output_path);
write_file(output_path, dSpecial, sizeof(dSpecial));

// Dungeon transparency.
sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_transparency.bin", g.dlvl, g.quest_id, g.seed, g.setlvl);
printf("creating '%s'\n", output_path);
write_file(output_path, dTransVal, sizeof(dTransVal));
}
}

void testgen() {
printf("testgen\n");
gen_drlg_l1_tests();
}

void write_file(char *path, void *buf, int size) {
FILE *f = fopen(path, "wb");
if (f == NULL) {
fprintf(stderr, "unable to create file %s", path);
exit(1);
}
if (fwrite(buf, 1, size, f) != size) {
fprintf(stderr, "unable to write to file %s", path);
exit(1);
}
fclose(f);
}
Loading