Skip to content
Merged
Prev Previous commit
Next Next commit
tests: Add unitzx.tap
The assembler tests can now be run directly on the spectrum.  The
test data is stored in data files created by the test_content_zx
tool.  It is expected to be in the same directory as unitzx.tap.

Signed-off-by: Mark Ryan <[email protected]>
  • Loading branch information
markdryan committed Nov 6, 2022
commit b7efb913d66a96ec43a8ed4a0974059aacb741af
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ unittests
salink
saimport
saexport
test_content_zx
SAIMPORT
SAEXPORT
SAIMPORT.X
SAEXPORT.X
build.sh
compile.sh
build/specasm
build/release
build/unitzx
.DS_Store
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ SAEXPORT =\
SALINK =\
salink.c

TEST_CONTENT_ZX =\
test_content.c \
test_content_zx.c

CFLAGS += -Wall -MMD -DUNITTESTS -Isrc

all: unittests saimport saexport salink
Expand All @@ -46,6 +50,9 @@ saexport: $(BASE:%.c=%.o) $(COMMON:%.c=%.o) $(POSIX:%.c=%.o) $(SAEXPORT:%.c=%.o)
salink: $(BASE:%.c=%.o) $(POSIX:%.c=%.o) $(SALINK:%.c=%.o)
$(CC) $(CFLAGS) -o $@ $^

test_content_zx: $(TEST_CONTENT_ZX:%.c=%.o)
$(CC) $(CFLAGS) -o $@ $^

clean:
- rm *.d *.o unittests saimport saexport salink

Expand All @@ -56,3 +63,4 @@ clean:
-include $(SAIMPORT:%.c=%.d)
-include $(SAEXPORT:%.c=%.d)
-include $(SALINK:%.c=%.d)
-include $(TEST_CONTENT_ZX:%.c=%.d)
25 changes: 23 additions & 2 deletions build/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
VPATH=../src

.PHONY: all
all: specasm.tap salink.tap SAEXPORT SAIMPORT
all: specasm.tap salink.tap unitzx.tap SAEXPORT SAIMPORT

CC=zcc
CFLAGS=+zx -SO2 --opt-code-size --max-allocs-per-node200000 -Cs "--disable-warning 85" -clib=sdcc_iy
Expand Down Expand Up @@ -42,20 +42,33 @@ SAIMPORT = \
peer_zx.o \
saimport.o

UNITZX = \
error.o \
state_base.o \
line.o \
state.o \
peer_file_zx.o \
peer_zx.o \
unittests_zx.o


specasm.tap: $(SPECASM)
$(CC) $(CFLAGS) -zorg=24550 -startup=31 -o specasm $^ -create-app -Cz--merge=../bas/SPECLD.TAP

salink.tap: $(SALINK)
$(CC) $(CFLAGS) -zorg=24000 -startup=31 -o salink $^ -create-app

unitzx.tap: $(UNITZX)
$(CC) $(CFLAGS) -zorg=24000 -startup=31 -o unitzx $^ -create-app

SAEXPORT: $(SAEXPORT)
$(CC) $(CFLAGS) -startup=30 -o $@ $(SAEXPORT) -subtype=dotx -Cz"--clean" -create-app

SAIMPORT: $(SAIMPORT)
$(CC) $(CFLAGS) -startup=30 -o $@ $(SAIMPORT) -subtype=dotx -Cz"--clean" -create-app

clean:
- rm -rf specasm *.zip
- rm -rf specasm *.zip -rf unitzx
- rm *.X *.o *.bin *.tap SAIMPORT SAEXPORT

.PHONY: release
Expand All @@ -67,3 +80,11 @@ release:
cp ../bas/INSTALL release/specasm
cp ../bas/REMOVE release/specasm
cd release && zip -r specasm.zip specasm

.PHONY: tests
tests:
- rm -rf unitzx
mkdir unitzx
cd .. && make -f Makefile test_content_zx
../test_content_zx unitzx
cp unitzx.tap unitzx
158 changes: 158 additions & 0 deletions src/test_content_zx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* Copyright contributors to Specasm
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "test_content.h"
#include "test_content_zx.h"

static int prv_make_opcode_file(const char *path)
{
size_t i;
char *fname;
int retval = 1;
FILE *f = NULL;
uint16_t count;
const char *name = "test_op";

fname = malloc(strlen(path) + strlen(name) + 2);
if (!fname)
return 1;

sprintf(fname, "%s/%s", path, name);

f = fopen(fname, "w");
if (!f) {
fprintf(stderr, "Unable to open %s for writing\n", fname);
goto cleanup;
}

count = (uint16_t) opcode_tests_count;
if (fwrite(&count, sizeof(count), 1, f) < 1) {
fprintf(stderr, "Failed to write to %s\n", fname);
goto cleanup;
}

for (i = 0; i < opcode_tests_count; i++) {
const test_t *t = &opcode_tests[i];
test_zx_t zx_test;

if (strlen(t->source) > SPECASM_LINE_MAX_LEN) {
fprintf(stderr, "%s too long\n", t->source);
goto cleanup;
}

if (strlen(t->str) > SPECASM_LINE_MAX_LEN) {
fprintf(stderr, "%s too long\n", t->str);
goto cleanup;
}

strcpy(zx_test.source, t->source);
strcpy(zx_test.str, t->str);
zx_test.size = (uint8_t) t->size;
memcpy(zx_test.op_code, t->op_code, 4);

if (fwrite(&zx_test, sizeof(zx_test), 1, f) < 1) {
fprintf(stderr, "Failed to write to %s\n", fname);
goto cleanup;
}
}

retval = fclose(f);
f = NULL;

cleanup:

if (f)
(void) fclose(f);

free(fname);

return retval;
}

static int prv_make_bad_test_file(const char *path)
{
size_t i;
char *fname;
int retval = 1;
FILE *f = NULL;
uint16_t count;
const char *name = "test_bad";

fname = malloc(strlen(path) + strlen(name) + 2);
if (!fname)
return 1;

sprintf(fname, "%s/%s", path, name);

f = fopen(fname, "w");
if (!f) {
fprintf(stderr, "Unable to open %s for writing\n", fname);
goto cleanup;
}

count = (uint16_t) bad_tests_count;
if (fwrite(&count, sizeof(count), 1, f) < 1) {
fprintf(stderr, "Failed to write to %s\n", fname);
goto cleanup;
}

for (i = 0; i < bad_tests_count; i++) {
const bad_test_t *t = &bad_tests[i];
bad_test_zx_t zx_test;

if (strlen(t->source) > SPECASM_LINE_MAX_LEN) {
fprintf(stderr, "%s too long\n", t->source);
goto cleanup;
}

strcpy(zx_test.source, t->source);
zx_test.error = t->error;

if (fwrite(&zx_test, sizeof(zx_test), 1, f) < 1) {
fprintf(stderr, "Failed to write to %s\n", fname);
goto cleanup;
}
}

retval = fclose(f);
f = NULL;

cleanup:

if (f)
(void) fclose(f);

free(fname);

return retval;
}

int main(int argc, char *argv[])
{
if (argc != 2) {
fprintf(stderr, "usage: test_content_zx path\n");
return 1;
}

int retval = prv_make_opcode_file(argv[1]) |
prv_make_bad_test_file(argv[1]);

return retval;
}
39 changes: 39 additions & 0 deletions src/test_content_zx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright contributors to Specasm
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef TEST_CONTENT_ZX_H
#define TEST_CONTENT_ZX_H

#include <stdint.h>

#include "line.h"

struct test_zx_t_ {
char source[SPECASM_LINE_MAX_LEN + 1];
char str[SPECASM_LINE_MAX_LEN + 1];
uint8_t size;
uint8_t op_code[4];
};
typedef struct test_zx_t_ test_zx_t;

struct bad_test_zx_t_ {
char source[SPECASM_LINE_MAX_LEN + 1];
specasm_error_t error;
};
typedef struct bad_test_zx_t_ bad_test_zx_t;


#endif
Loading