Skip to content

Commit

Permalink
[6model/c] many small build and testing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mberends committed Aug 21, 2011
1 parent d50b8cb commit 816dda0
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 80 deletions.
6 changes: 5 additions & 1 deletion c/t/01-toolchain/01a-cc.c → c/t/01-toolchain/01a-cc.t.c
Expand Up @@ -181,7 +181,11 @@ create_lib()
#else #else
status = system("gcc -c -fPIC -o testlib.o testlib.c"); /* Unix */ status = system("gcc -c -fPIC -o testlib.o testlib.c"); /* Unix */
if (status==0) { if (status==0) {
status = system("cc -shared -s -o testlib.so testlib.o"); #if defined( __APPLE__ )
status = system("cc -shared -o testlib.so testlib.o");
#else
status = system("cc -shared -s -o testlib.so testlib.o");
#endif
} }
if (status==0) { if (status==0) {
status = system("rm testlib.o"); status = system("rm testlib.o");
Expand Down
@@ -1,5 +1,9 @@
/* 01b-timing.c */ /* 01b-timing.c */


/* TODO: try these functions on Win32 for better precision: */
/* _ftime usleep QueryPerformanceCounter QueryPerformanceFrequency */


#include <stdio.h> /* sprintf */ #include <stdio.h> /* sprintf */
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
Expand All @@ -18,13 +22,13 @@ seconds_microseconds_sleep()
int microseconds1, microseconds2, microseconds3, microseconds4, microseconds5; int microseconds1, microseconds2, microseconds3, microseconds4, microseconds5;
char message[80]; char message[80];


/* Read the clock twice in quick succession, sleep for 1 second, */ /* Read the clock multiple times with various delays in between. */
/* then read the clock a third time. Report the differences */ /* Check that the time differences are within reason */
/* between the times and verify that the sleep was about 1 sec. */
#ifdef _WIN32 #ifdef _WIN32
FILETIME time1, time2, time3, time4, time5; FILETIME time1, time2, time3, time4, time5;
GetSystemTimeAsFileTime(&time1); /* * 100ns since 1601-01-01 */ GetSystemTimeAsFileTime(&time1); /* * 100ns since 1601-01-01 */
GetSystemTimeAsFileTime(&time2); GetSystemTimeAsFileTime(&time2);
_ftime(); // TODO
Sleep(0); /* 0 milliseconds */ Sleep(0); /* 0 milliseconds */
GetSystemTimeAsFileTime(&time3); GetSystemTimeAsFileTime(&time3);
Sleep(1); /* 1 millisecond */ Sleep(1); /* 1 millisecond */
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 18 additions & 5 deletions c/t/Test.h
Expand Up @@ -35,27 +35,40 @@ int _test_number=0; /* yes, namespace pollution. patches welcome ;-) */
#define \ #define \
ok(flag,desc) \ ok(flag,desc) \
printf("%sok %d - %s\n", \ printf("%sok %d - %s\n", \
flag?"":"not ",++_test_number,desc) flag?"":"not ",++_test_number,desc); \
fflush(stdout)


#define \ #define \
is_ii(got,expected,desc) \ is_ii(got,expected,desc) \
printf("%sok %d - %s\n", \ printf("%sok %d - %s\n", \
got==expected?"":"not ",++_test_number,desc); \ got==expected?"":"not ",++_test_number,desc); \
if(got!=expected) \ if(got!=expected) \
printf("# got : %d\n# expected : %d\n", got, expected) printf("# got : %d\n# expected : %d\n", got, expected); \
fflush(stdout)

#define \
is_ll(got,expected,desc) \
printf("%sok %d - %s\n", \
got==expected?"":"not ",++_test_number,desc); \
if(got!=expected) \
printf("# got : %ld\n# expected : %ld\n", got, expected); \
fflush(stdout)


#define \ #define \
is_ss(got,expected,desc) \ is_ss(got,expected,desc) \
printf("%sok %d - %s\n", \ printf("%sok %d - %s\n", \
strcmp(got,expected)?"not ":"",++_test_number,desc) strcmp(got,expected)?"not ":"",++_test_number,desc); \
fflush(stdout)


#define \ #define \
isnt_pp(got,expected,desc) \ isnt_pp(got,expected,desc) \
printf("%sok %d - %s\n", \ printf("%sok %d - %s\n", \
(got!=expected)?"":"not ", ++_test_number, desc) (got!=expected)?"":"not ", ++_test_number, desc); \
fflush(stdout)


#define \ #define \
diag(message) \ diag(message) \
printf("# %s\n", message) printf("# %s\n", message); \
fflush(stdout)


/* end of Test.h */ /* end of Test.h */
39 changes: 20 additions & 19 deletions c/tools/build/Configure.c
@@ -1,27 +1,28 @@
/* Configure.c */ /* Configure.c */
/* Compiled and run by 6model/c/Configure.(sh|bat) */ /* Compiled and run by 6model/c/Configure.{sh,bat} */


/* This program (Configure) uses environment variables and C macros */ /* This program (Configure) uses environment variables and C macros */
/* to autodetect the operating system, compiler and other utilities */ /* to autodetect the operating system, compiler and other utilities */
/* that can be used to build your software. It then creates your */ /* that can be used to build your software. It then creates your */
/* Makefile based on a template (Makefile.in). To work also with */ /* Makefile based on a template (Makefile.in). To also work with */
/* non-GNU systems such as Microsoft Visual C++, it follows the */ /* non-GNU systems such as Microsoft C/C++, it follows the style of */
/* style of Automake and Autoconf, but is written in only C and does */ /* Automake and Autoconf, but is written only in C and does not rely */
/* not rely on other tools such as M4. */ /* on other tools such as M4. */


/* This work will never be finished. Reliable autodetection is hard. */ /* This work will never be complete, because autodetection is hard. */
/* There are always newer environments and tools to try out. */ /* New software emerges, environments and tools evolve, users make */
/* Systems usually predefine some variables and macros. Users might */ /* unforeseen choices. Monitor the changes through regular testing. */
/* make the same definitions. */

/* Currently verified to work with:
/* Currently works with: * GNU C compiler on Linux, OS X and Windows (as MinGW).
*
* MinGW * MinGW
* http://mingw.org/ * http://mingw.org/
* Currently based on GCC 4.5.2, 85MB disk. * Currently based on GCC 4.5.2, 85MB disk.
* Targets Win32 libraries, no Posix emulation or dlopen. * Targets Win32 libraries, no Posix emulation or dlopen.
* (older version bundled with Git full install) * (older version bundled with Git full install)
* Microsoft Visual C++ Express Edition 1-2GB RAM, 3GB disk * Microsoft Visual C++ Express Edition 1-2GB RAM
* Registration required to avoid de-activation after 30 days. Downloads a 3.2MB web installer. * Registration required to avoid de-activation after 30 days. Downloads a 3.2MB web installer.
* http://www.microsoft.com/express/vc/ do not need optional SQL express. * http://www.microsoft.com/express/vc/ do not need optional SQL express.
* Also installs Windows Installer 4.5, .NET Framework 4, SQL Server Compact 3.5, Help Viewer 1.0 * Also installs Windows Installer 4.5, .NET Framework 4, SQL Server Compact 3.5, Help Viewer 1.0
Expand Down Expand Up @@ -66,7 +67,7 @@ void
detection(void) detection(void)
{ {
int processors = 0; int processors = 0;
#if defined( _WIN32 ) #if defined( _WIN32 ) && ! defined( _OPENMP )
SYSTEM_INFO sysinfo; /* declare up here because MSC hates it lower */ SYSTEM_INFO sysinfo; /* declare up here because MSC hates it lower */
#endif #endif
printf("Configure detects the following:\n"); printf("Configure detects the following:\n");
Expand Down Expand Up @@ -224,7 +225,7 @@ makefile_convert(char * programfilename, char * templatefilename,
trans(&makefiletext, "t/02-components", "t\\02-components"); trans(&makefiletext, "t/02-components", "t\\02-components");
#endif #endif
#if defined( _MSC_VER ) #if defined( _MSC_VER )
trans(&makefiletext, "$(O) ", "$(O)"); trans(&makefiletext, "$(OUTFILE) ", "$(OUTFILE)");
#endif #endif
printf(" %s: writing to %s\n", programfilename, outputfilename); printf(" %s: writing to %s\n", programfilename, outputfilename);
squirt(makefiletext, outputfilename); squirt(makefiletext, outputfilename);
Expand Down Expand Up @@ -341,16 +342,16 @@ main(int argc, char * argv[])


/* /*
* TODO * TODO
*
* Explore more Win32 C compilers and toolchains * Explore more C compilers and toolchains
* http://www.thefreecountry.com/compilers/cpp.shtml * http://www.thefreecountry.com/compilers/cpp.shtml
* lcc-win32 http://www.cs.virginia.edu/~lcc-win32/ * lcc-win32 http://www.cs.virginia.edu/~lcc-win32/
* Borland (Registration required) * Borland (Registration required)
* Tiny C Compiler http://bellard.org/tcc/ * Tiny C Compiler http://bellard.org/tcc/
* OpenWatcom http://www.openwatcom.org/index.php/Download * OpenWatcom http://www.openwatcom.org/index.php/Download
* Digital Mars http://www.digitalmars.com/download/freecompiler.html * Digital Mars http://www.digitalmars.com/download/freecompiler.html
*
*/ */




/* See also: */ /* See also: */
Expand Down
48 changes: 24 additions & 24 deletions c/tools/build/Makefile.in
Expand Up @@ -20,32 +20,32 @@ OPENMP = @openmp@
all: test all: test


# Recipes to build executables # Recipes to build executables
t/01-toolchain/01a-cc.exe: t/01-toolchain/01a-cc.c t/Test.h t/01-toolchain/01a-cc.t.exe: t/01-toolchain/01a-cc.t.c t/Test.h
$(CC) $(OUTFILE) t/01-toolchain/01a-cc.exe t/01-toolchain/01a-cc.c $(CC) $(OUTFILE) t/01-toolchain/01a-cc.t.exe t/01-toolchain/01a-cc.t.c
-$(RM_RF) 01a-cc.obj -$(RM_RF) 01a-cc.t.obj


t/01-toolchain/01b-timing.exe: t/01-toolchain/01b-timing.c t/Test.h t/01-toolchain/01b-timing.t.exe: t/01-toolchain/01b-timing.t.c t/Test.h
$(CC) $(OUTFILE) t/01-toolchain/01b-timing.exe t/01-toolchain/01b-timing.c $(CC) $(OUTFILE) t/01-toolchain/01b-timing.t.exe t/01-toolchain/01b-timing.t.c
-$(RM_RF) 01b-timing.obj -$(RM_RF) 01b-timing.t.obj


t/01-toolchain/01c-osthreads.exe: t/01-toolchain/01c-osthreads.c t/Test.h t/01-toolchain/01c-osthreads.t.exe: t/01-toolchain/01c-osthreads.t.c t/Test.h
$(CC) $(THREADS) $(OPENMP) $(OUTFILE) t/01-toolchain/01c-osthreads.exe t/01-toolchain/01c-osthreads.c $(CC) $(THREADS) $(OPENMP) $(OUTFILE) t/01-toolchain/01c-osthreads.t.exe t/01-toolchain/01c-osthreads.t.c
-$(RM_RF) 01c-osthreads.obj -$(RM_RF) 01c-osthreads.t.obj


t/02-components/02a-threads.exe: t/02-components/02a-threads.c \ t/02-components/02a-threads.t.exe: t/02-components/02a-threads.t.c \
src/threads.h src/threads.c src/timing.c src/timing.h t/Test.h src/threads.h src/threads.c src/timing.c src/timing.h t/Test.h
$(CC) $(THREADS) $(OUTFILE) t/02-components/02a-threads.exe src/threads.c src/timing.c t/02-components/02a-threads.c $(CC) $(THREADS) $(OUTFILE) t/02-components/02a-threads.t.exe src/threads.c src/timing.c t/02-components/02a-threads.t.c
-$(RM_RF) threads.obj 02a-threads.obj -$(RM_RF) threads.obj 02a-threads.t.obj


t/02-components/02b-hashtable.exe: t/02-components/02b-hashtable.c \ t/02-components/02b-hashtable.t.exe: t/02-components/02b-hashtable.t.c \
src/hashtable.h src/hashtable.c t/Test.h src/hashtable.h src/hashtable.c t/Test.h
$(CC) $(OUTFILE) t/02-components/02b-hashtable.exe src/hashtable.c t/02-components/02b-hashtable.c $(CC) $(OUTFILE) t/02-components/02b-hashtable.t.exe src/hashtable.c t/02-components/02b-hashtable.t.c
-$(RM_RF) hashtable.obj 02b-hashtable.obj -$(RM_RF) hashtable.obj 02b-hashtable.t.obj


t/02-components/02c-heapmanager.exe: t/02-components/02c-heapmanager.c \ t/02-components/02c-mem.t.exe: t/02-components/02c-mem.t.c \
src/heapmanager.h src/heapmanager.c t/Test.h src/mem.h src/mem.c t/Test.h
$(CC) $(OUTFILE) t/02-components/02c-heapmanager.exe src/heapmanager.c t/02-components/02c-heapmanager.c $(CC) $(OUTFILE) t/02-components/02c-mem.t.exe src/mem.c t/02-components/02c-mem.t.c
-$(RM_RF) heapmanager.obj 02b-heapmanager.obj -$(RM_RF) mem.obj 02b-mem.t.obj


tools/build/prove$(EXE): tools/build/prove.c tools/build/prove$(EXE): tools/build/prove.c
$(CC) $(OUTFILE) tools/build/prove$(EXE) tools/build/prove.c $(CC) $(OUTFILE) tools/build/prove$(EXE) tools/build/prove.c
Expand All @@ -58,13 +58,13 @@ test: test01 test02
# The test01 target checks that the C compiler and so on perform the # The test01 target checks that the C compiler and so on perform the
# functions needed by the rest of the code. It is generally unnecessary # functions needed by the rest of the code. It is generally unnecessary
# to run this test, but is useful when troubleshooting. # to run this test, but is useful when troubleshooting.
test01: t/01-toolchain/01a-cc.exe t/01-toolchain/01b-timing.exe \ test01: t/01-toolchain/01a-cc.t.exe t/01-toolchain/01b-timing.t.exe \
t/01-toolchain/01c-osthreads.exe tools/build/prove$(EXE) t/01-toolchain/01c-osthreads.t.exe tools/build/prove$(EXE)
tools/build/prove -e "" --ext ".exe" t/01-toolchain tools/build/prove -e "" --ext ".exe" t/01-toolchain


# The test02 target validates the internal libraries of 6model/c # The test02 target validates the internal libraries of 6model/c
test02: t/02-components/02a-threads.exe \ test02: t/02-components/02a-threads.t.exe t/02-components/02b-hashtable.t.exe \
t/02-components/02b-hashtable.exe tools/build/prove$(EXE) tools/build/prove$(EXE)
tools/build/prove -e "" --ext ".exe" t/02-components tools/build/prove -e "" --ext ".exe" t/02-components


# Miscellaneous targets # Miscellaneous targets
Expand All @@ -81,7 +81,7 @@ help:
@echo In this 6model/c directory you can make the following targets: @echo In this 6model/c directory you can make the following targets:
@echo "test - general test as far as 6model has been developed" @echo "test - general test as far as 6model has been developed"
@echo "test01 - test the toolchain, eg C compiler, threads, ICU etc" @echo "test01 - test the toolchain, eg C compiler, threads, ICU etc"
@echo "test02 - test 6model components, eg hashtable, heapmanager etc" @echo "test02 - test 6model components, eg hashtable, mem etc"
@echo "clean - remove all generated files except this Makefile" @echo "clean - remove all generated files except this Makefile"
@echo "realclean - remove all generated files including this Makefile" @echo "realclean - remove all generated files including this Makefile"
@echo "help - you already found this" @echo "help - you already found this"

0 comments on commit 816dda0

Please sign in to comment.