Add a directory for tests that exercise the supported C standard differences.

As a first test added the snippet given in issue #1670
This commit is contained in:
mrdudz 2022-05-08 19:29:27 +02:00
parent 3640beaa46
commit 1abb5f4734
3 changed files with 103 additions and 0 deletions

View File

@ -12,6 +12,13 @@ compiler is working as expected (when the tests behave as described):
/val - The bulk of tests are contained here, individual tests should exit with
an exit code of EXIT_SUCCESS when they pass, or EXIT_FAILURE on error.
/standard - like the tests in /val, the tests must exit with EXIT_SUCCESS on
success. Unlike the tests in /val these are not compiled for every
combination of optimizer options, but instead always with -Osir and then
for each supported C-standard (C89, C99, CC65). The goal is to use these
to check for regressions in standard conformance of the compiler and the
library.
/ref - These tests produce output that must be compared with reference output.
/err - contains tests that MUST NOT compile

63
test/standard/Makefile Normal file
View File

@ -0,0 +1,63 @@
# Makefile for the regression tests that return an error code on failure
ifneq ($(shell echo),)
CMD_EXE = 1
endif
ifdef CMD_EXE
S = $(subst /,\,/)
NULLDEV = nul:
MKDIR = mkdir $(subst /,\,$1)
RMDIR = -rmdir /s /q $(subst /,\,$1)
else
S = /
NULLDEV = /dev/null
MKDIR = mkdir -p $1
RMDIR = $(RM) -r $1
endif
ifdef QUIET
.SILENT:
NULLOUT = >$(NULLDEV)
NULLERR = 2>$(NULLDEV)
endif
SIM65FLAGS = -x 5000000000 -c
CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65)
CA65 := $(if $(wildcard ../../bin/ca65*),..$S..$Sbin$Sca65,ca65)
LD65 := $(if $(wildcard ../../bin/ld65*),..$S..$Sbin$Sld65,ld65)
SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65)
WORKDIR = ../../testwrk/standard
OPTIONS = c89 c99 cc65
.PHONY: all clean
SOURCES := $(wildcard *.c)
TESTS = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).6502.prg))
#TESTS += $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).65c02.prg))
all: $(TESTS)
$(WORKDIR):
$(call MKDIR,$(WORKDIR))
define PRG_template
$(WORKDIR)/%.$1.$2.prg: %.c | $(WORKDIR)
$(if $(QUIET),echo standard/$$*.$1.$2.prg)
$(CC65) -t sim$2 $$(CC65FLAGS) -Osir --add-source --standard $1 -o $$(@:.prg=.s) $$< $(NULLERR)
$(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR)
$(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR)
$(SIM65) $(SIM65FLAGS) $$@ > $(WORKDIR)/$$@.out
endef # PRG_template
$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),6502)))
#$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02)))
clean:
@$(call RMDIR,$(WORKDIR))

33
test/standard/bug1670.c Normal file
View File

@ -0,0 +1,33 @@
/* #1670 - Standard headers contain non standard identifiers in C89/C99 mode */
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#if __CC65_STD__ != __CC65_STD_CC65__
/* implement our own clock_gettime, using a different signature than the POSIX one */
const char* clock_gettime(void)
{
static char buf[32];
struct tm *my_tm;
#if 0
/* FIXME: this will not work in the simulator */
time_t t = time(NULL);
#else
time_t t = 0x12345678;
#endif
my_tm = localtime(&t);
printf("%2d:%2d:%2d\n", my_tm->tm_hour, my_tm->tm_min, my_tm->tm_sec);
strftime(buf, sizeof(buf), "<%H:%M:%S>", my_tm);
return buf;
}
#endif
int main(void)
{
#if __CC65_STD__ != __CC65_STD_CC65__
printf("The time is %s\n", clock_gettime());
#endif
return EXIT_SUCCESS;
}