diff --git a/Makefile b/Makefile index f2695db..1440dd9 100644 --- a/Makefile +++ b/Makefile @@ -7,25 +7,26 @@ ifneq (,$(wildcard /proc/sys/fs/binfmt_misc/WSLInterop)) else JAR_PATH = /usr/share/kaitai-struct-compiler/lib/* endif -all: src-animal/libanimal.so +KSY := animal fake +LIBS := $(foreach ksy,$(KSY),test_artifacts/lib$(ksy).so) -src-animal/libanimal.so: $(BUILD) src-animal/animal.cpp - PYTHONPATH=$$PYTHONPATH:local $(BUILD) src-animal/animal.cpp -b build +test_artifacts/lib%.so: test_artifacts/%.cpp $(BUILD) + PYTHONPATH=$$PYTHONPATH:local $(BUILD) $< -b build $(BUILD): pip install . -t local -src-animal/animal.cpp: $(JAVA_CLASSES) - java -cp kaitai_struct_compiler/jvm/target/scala-2.12/kaitai-struct-compiler_2.12-0.11-SNAPSHOT.jar:$(JAR_PATH) io.kaitai.struct.JavaMain -t awkward --outdir src-animal example_data/schemas/animal.ksy +test_artifacts/%.cpp: example_data/schemas/%.ksy $(JAVA_CLASSES) + java -cp kaitai_struct_compiler/jvm/target/scala-2.12/kaitai-struct-compiler_2.12-0.11-SNAPSHOT.jar:$(JAR_PATH) io.kaitai.struct.JavaMain -t awkward --outdir test_artifacts $< $(JAVA_CLASSES): cd kaitai_struct_compiler && sbt package -test: src-animal/libanimal.so +test: $(LIBS) pytest list: - @LC_ALL=C $(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' + @LC_ALL=C $(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' clean: - rm -rf local src-animal && cd kaitai_struct_compiler && rm -fr js/target/ jvm/target/ project/project/ project/target/ target/ .bsp/ + rm -rf local test_artifacts && cd kaitai_struct_compiler && rm -fr js/target/ jvm/target/ project/project/ project/target/ target/ .bsp/ diff --git a/src/awkward_kaitai/data/CMakeLists.txt b/src/awkward_kaitai/data/CMakeLists.txt index 709021e..8c6f827 100644 --- a/src/awkward_kaitai/data/CMakeLists.txt +++ b/src/awkward_kaitai/data/CMakeLists.txt @@ -52,7 +52,7 @@ if(NOT awkward-headers_POPULATED) EXCLUDE_FROM_ALL) endif() -file(GLOB KAITAI_SOURCE_FILES CONFIGURE_DEPENDS "${KAITAI_DIR}/*.cpp") +file(GLOB KAITAI_SOURCE_FILES CONFIGURE_DEPENDS "${KAITAI_DIR}/${KAITAI_NAME}.cpp") # Create a shared library add_library("${KAITAI_NAME}" SHARED ${KAITAI_SOURCE_FILES}) diff --git a/tests/test_animal.py b/tests/test_animal.py index 8791ebc..5b2f615 100644 --- a/tests/test_animal.py +++ b/tests/test_animal.py @@ -8,7 +8,7 @@ def test_animal(): animal = awkward_kaitai.Reader( - "src-animal/libanimal.so" + "test_artifacts/libanimal.so" ) # pass the path of the shared file awkward_array = animal.load("example_data/data/animal.raw") diff --git a/tests/test_fake.py b/tests/test_fake.py new file mode 100644 index 0000000..f98b2cb --- /dev/null +++ b/tests/test_fake.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +import sys + +import numpy as np + +sys.path.append("local") +import awkward_kaitai + + +def test_fake(): + reader = awkward_kaitai.Reader("test_artifacts/libfake.so") + awkward_array = reader.load("example_data/data/fake.raw") + + assert len(awkward_array.fakeA__Zpoints.pointA__Zx[0]) == 3000 + assert awkward_array.fakeA__Zpoints.pointA__Zy[0][0] == 2 + assert awkward_array.fakeA__Zpoints.pointA__Zz.to_numpy().sum() == 66000 + + expected_array = np.array( + [(1, 2, 3), (10, 20, 30), (11, 22, 33)] * 1000, + dtype=[("pointA__Zx", "u4"), ("pointA__Zy", "u4"), ("pointA__Zz", "u4")], + ) + + np.testing.assert_array_equal( + awkward_array.fakeA__Zpoints.to_numpy()[0], expected_array + )