Initial entry
authordick <none@none>
Fri, 24 Jun 1988 15:40:41 +0000 (15:40 +0000)
committerdick <none@none>
Fri, 24 Jun 1988 15:40:41 +0000 (15:40 +0000)
util/int/test/Makefile [new file with mode: 0644]
util/int/test/READ_ME [new file with mode: 0644]
util/int/test/args.c [new file with mode: 0644]
util/int/test/awa.p [new file with mode: 0644]
util/int/test/fork2.c [new file with mode: 0644]
util/int/test/ioc0.c [new file with mode: 0644]
util/int/test/prtime.c [new file with mode: 0644]
util/int/test/set.c [new file with mode: 0644]
util/int/test/sig.c [new file with mode: 0644]

diff --git a/util/int/test/Makefile b/util/int/test/Makefile
new file mode 100644 (file)
index 0000000..fa6477d
--- /dev/null
@@ -0,0 +1,28 @@
+# $Header$
+
+EM =           /usr/em#        # EM tree
+
+.SUFFIXES:     .em22 .em24 .em44
+
+.c.em22:
+       $(EM)/bin/em22 $*.c -o $*.em22
+
+.p.em22:
+       $(EM)/bin/em22 $*.p -o $*.em22
+
+.c.em24:
+       $(EM)/bin/em24 $*.c -o $*.em24
+
+.p.em24:
+       $(EM)/bin/em24 $*.p -o $*.em24
+
+.c.em44:
+       $(EM)/bin/em44 $*.c -o $*.em44
+
+.p.em44:
+       $(EM)/bin/em44 $*.p -o $*.em44
+
+clean:
+       rm -f e.out core mon.out int.mess int.log int.core int.tally \
+               *.k *.m *.o *.s *.em?? a.out
+
diff --git a/util/int/test/READ_ME b/util/int/test/READ_ME
new file mode 100644 (file)
index 0000000..3dbb6ff
--- /dev/null
@@ -0,0 +1,16 @@
+# $Header$
+
+Various small but non-trivial test programs that have been useful in
+testing and debugging the EM interpreter.
+
+E.out format files are identified by the suffices .em22, .em24 and .em44.
+The Makefile will produce these if called like:
+
+       make X.em24
+
+where X.[cp] is a C or Pascal program.  The Makefile has no facilities
+for multi-file programs.
+
+Awa.p is used by the Makefile in ../src, to do everyday testing; it must be
+present.
+
diff --git a/util/int/test/args.c b/util/int/test/args.c
new file mode 100644 (file)
index 0000000..82a6b32
--- /dev/null
@@ -0,0 +1,32 @@
+/* $Header$ */
+
+/*
+       Test access to args and environ
+*/
+
+extern char **environ;
+
+main(argc, argv, envp)
+       char **argv, **envp;
+{
+       int i;
+
+       printf("# of args: %d\n", argc);
+
+       printf("\n");
+       for (i = 0; argv[i] != 0; i++)
+               printf("$%d=%s\n", i, argv[i]);
+
+       printf("\n");
+       for (i = 0; envp[i] != 0; i++)
+               printf("%s\n", envp[i]);
+
+       if (envp != environ)    {
+               printf("\n");
+               printf("different environment from `environ':\n");
+               for (i = 0; envp[i] != 0; i++)
+                       printf("%s\n", envp[i]);
+               printf("\n");
+       }
+       exit(0);
+}
diff --git a/util/int/test/awa.p b/util/int/test/awa.p
new file mode 100644 (file)
index 0000000..ad011db
--- /dev/null
@@ -0,0 +1,67 @@
+{ $Header$ }
+
+program ArrayWithoutArray(input, output);
+{      We simulate a (read-only) array by constructing a mapping
+       function   map(n)   which yields the n-th element.
+       We demonstrate its existence by first printing the length
+       of the array and then its contents.
+       This technique was first introduced by F.E.J. Kruseman-Aretz,
+       in the early sixties.
+}
+
+procedure Action(n: integer; function map(n: integer): integer);
+       {       Action is called when the construction of the virtual
+               array is finished.  Actually, all elements now reside
+               on the stack.
+               n:      the length of the array,
+               map:    the mapping function.
+       }
+       var i: integer;
+       begin   { show that the whole array is still there }
+               writeln('#elems:', n);
+               write('elems:');
+               for i:= 1 to n do
+                       write(map(i))
+       end {Action};
+
+procedure Construct(n: integer; function oldmap(n: integer): integer);
+       {       For each value read, Construct will store that value and
+               declare a new map function, composed of the old one
+               augmented by the new value.
+               It then calls itself recursively for the next value.
+               
+               n:      element number on this level
+               oldmap: map for 1 .. n-1
+       }
+       var x: integer;         { the value stored at level n }
+       
+       function newmap(i: integer): integer;
+               { yields elements stored so far }
+               begin
+                       if      { the i-th element is kept on this level}
+                               i = n
+                       then    { yield it }
+                               newmap := x
+                       else    { try lower down the road }
+                               newmap := oldmap(i)
+               end {newmap};
+       
+       begin
+               read(x);
+               if      { it is a valid value }
+                       x >= 0
+               then    { we continue reading values and constructing maps }
+                       Construct(n + 1, newmap)
+               else    { we stop reading and pass the info on to Action }
+                       Action(n - 1, newmap)
+       end {Construct};
+
+function EmptyMap(n: integer): integer;
+       begin
+               writeln('Illegal index', n, '; 0 yielded.');
+               EmptyMap := 0
+       end {EmptyMap};
+
+begin
+       Construct(1, EmptyMap)
+end.
diff --git a/util/int/test/fork2.c b/util/int/test/fork2.c
new file mode 100644 (file)
index 0000000..e9ec4b6
--- /dev/null
@@ -0,0 +1,40 @@
+/* $Header$ */
+
+/*
+       Test forking
+*/
+
+#include <signal.h>
+
+main()
+{
+    int i, b;
+    long a;
+
+    i = fork();
+    if( i == 0 ) {
+       printf( "kind 1\n" );
+       i = fork();
+       if( i == 0 ) {
+           printf( "kind 1.1\n" );
+           exit( 111 );
+       } else {
+           wait( &b );
+           printf( "h:%d, l:%d\n", (b&0xFF00)>>8, b&0xFF);
+           exit( 11 );
+       }
+    } else {
+       printf( "parent\n" );
+       i = fork();
+       if( i == 0 ) {
+           printf( "kind 2\n" );
+           exit( 22 );
+       } else {
+           a = wait( &b );
+           printf( "pid:%d, h:%d, l:%d\n", a, (b&0xFF00)>>8, b&0xFF);
+           a = wait( &b );
+           printf( "pid:%d, h:%d, l:%d\n", a, (b&0xFF00)>>8, b&0xFF);
+           exit( 99 );
+       }
+    }
+}
diff --git a/util/int/test/ioc0.c b/util/int/test/ioc0.c
new file mode 100644 (file)
index 0000000..341cedb
--- /dev/null
@@ -0,0 +1,36 @@
+/* $Header$ */
+
+/* Testing ioctl monitor call */
+#include       <sgtty.h>
+
+char sbuf[10];
+struct sgttyb old, ttyb;
+
+main()
+{
+   register i = 0;
+   char c;
+
+   if( ioctl( 1, TIOCGETP, &old ) != 0 ) {
+       write( 2, "ioctl ophalen mislukt\n", 22 );
+       exit( 100 );
+   }
+   write( 2, "Huidige status opgehaald\n", 25 );
+   ttyb = old;
+   ttyb.sg_flags &= ~ECHO;
+   if( ioctl( 1, TIOCSETP, &ttyb ) != 0 ) {
+       write( 2, "ioctl -echo mislukt\n", 20 );
+       exit( 100 );
+   }
+   write( 2, "Echo uitgezet\n", 14 );
+   write( 2, "geef input: ", 12 ); 
+   while( i<9 && (c = getchar()) != '\n' )
+       sbuf[i++] = c;
+   write( 1, sbuf, strlen(sbuf) );
+   if( ioctl( 1, TIOCSETP, &old ) != 0 ) {
+       write( 2, "ioctl reset mislukt\n", 20 );
+       exit( 100 );
+   }
+   write( 2, "Klaar\n", 6 );
+   exit( 0 );
+}
diff --git a/util/int/test/prtime.c b/util/int/test/prtime.c
new file mode 100644 (file)
index 0000000..0a1b117
--- /dev/null
@@ -0,0 +1,39 @@
+/* $Header$ */
+
+/*
+       Test access to fields in struct stat
+*/
+
+#include       <sys/types.h>
+#include       <sys/stat.h>
+#include       <time.h>
+extern char * ctime();
+
+main(argc, argv) char *argv[]; {
+
+       while (argc > 1)        {
+               prfiltime(argv[1]);
+               if (argc > 2)
+                       printf("\n");
+               argc--;
+               argv++;
+       }
+       exit(0);
+}
+
+prfiltime(name) char *name;    {
+       struct stat buf;
+
+       printf("%s: ", name);
+       if (stat(name, &buf) != 0)
+               printf(" not found\n");
+       else
+               prtime(&buf);
+}
+prtime(buf)
+       struct stat *buf;
+{
+       printf("%lu ", buf->st_mtime);
+       printf("%s\n", ctime(&buf->st_mtime));
+}
+
diff --git a/util/int/test/set.c b/util/int/test/set.c
new file mode 100644 (file)
index 0000000..be8322e
--- /dev/null
@@ -0,0 +1,29 @@
+/* $Header$ */
+
+/*
+       Test combination of signal and setjmp/longjmp
+*/
+
+#include <setjmp.h>
+#include <signal.h>
+
+jmp_buf jb;
+void a(), b(); 
+
+main()
+{
+       char c;
+
+        signal( SIGINT, a );
+        signal( SIGQUIT, b );
+       switch( setjmp( jb ) ) {
+           case 0: write( 1, "start\n", 6 ); break;
+           case 1: write( 1, "int\n", 4 ); break;
+           case 2: write( 1, "quit\n", 5 ); break;
+       }
+       while(read(0, &c, 1));
+       
+}
+
+void a(){ signal( SIGINT, a ); longjmp( jb, 1 ); }
+void b(){ signal( SIGQUIT, b ); longjmp( jb, 2 ); }
diff --git a/util/int/test/sig.c b/util/int/test/sig.c
new file mode 100644 (file)
index 0000000..32092b6
--- /dev/null
@@ -0,0 +1,27 @@
+/* $Header$ */
+
+#include <signal.h>
+
+/* testing signal(SIGINT, vang) */
+
+int handler();
+
+main()
+{
+       char *ch = "a\n";
+       
+       signal( SIGINT, handler );
+       while(1) {
+               write(1, ch, 2);
+               ch[0]++;
+               if (ch[0] > 'z')
+                       ch[0] = 'a';
+       }
+}
+
+handler()
+{
+       /* vang CTRL-C op */
+       write( 1, "Heb um gevangen\n", 16 );
+       signal( SIGINT, handler );
+}