svn commit: trunk/uClibc/test/misc

vapier at uclibc.org vapier at uclibc.org
Tue Feb 28 00:36:53 UTC 2006


Author: vapier
Date: 2006-02-27 16:36:51 -0800 (Mon, 27 Feb 2006)
New Revision: 14325

Log:
grab some tests from dalias

Added:
   trunk/uClibc/test/misc/popen.c
   trunk/uClibc/test/misc/time.c


Changeset:
Added: trunk/uClibc/test/misc/popen.c
===================================================================
--- trunk/uClibc/test/misc/popen.c	2006-02-28 00:28:55 UTC (rev 14324)
+++ trunk/uClibc/test/misc/popen.c	2006-02-28 00:36:51 UTC (rev 14325)
@@ -0,0 +1,47 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <signal.h>
+
+#define TEST(r, f, x, m) ( \
+((r) = (f)) == (x) || \
+(printf(__FILE__ ":%d: %s failed (" m ")\n", __LINE__, #f, r, x), err++, 0) )
+
+#define TEST_E(f) ( (errno = 0), (f) || \
+(printf(__FILE__ ":%d: %s failed (errno = %d)\n", __LINE__, #f, errno), err++, 0) )
+
+#define TEST_S(s, x, m) ( \
+!strcmp((s),(x)) || \
+(printf(__FILE__ ":%d: [%s] != [%s] (%s)\n", __LINE__, s, x, m), err++, 0) )
+
+static sig_atomic_t got_sig;
+
+static void handler(int sig)
+{
+	got_sig = 1;
+}
+
+int main(void)
+{
+	int i;
+	char foo[6];
+	char cmd[64];
+	int err = 0;
+	FILE *f;
+
+	TEST_E(f = popen("echo hello", "r"));
+	TEST_E(fgets(foo, sizeof foo, f));
+	TEST_S(foo, "hello", "child process did not say hello");
+	TEST(i, pclose(f), 0, "exit status %04x != %04x");
+
+	signal(SIGUSR1, handler);
+	snprintf(cmd, sizeof cmd, "read a ; test \"x$a\" = xhello && kill -USR1 %d", getpid());
+	TEST_E(f = popen(cmd, "w"));
+	TEST_E(fputs("hello", f) >= 0);
+	TEST(i, pclose(f), 0, "exit status %04x != %04x");
+	signal(SIGUSR1, SIG_DFL);
+	TEST(i, got_sig, 1, "child process did not send signal (%i!=%i)");
+
+	return err;
+}

Added: trunk/uClibc/test/misc/time.c
===================================================================
--- trunk/uClibc/test/misc/time.c	2006-02-28 00:28:55 UTC (rev 14324)
+++ trunk/uClibc/test/misc/time.c	2006-02-28 00:36:51 UTC (rev 14325)
@@ -0,0 +1,76 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+
+/* We use this instead of memcmp because some broken C libraries
+ * add additional nonstandard fields to struct tm... */
+ 
+int tm_cmp(struct tm tm1, struct tm tm2)
+{
+	return  tm1.tm_sec  != tm2.tm_sec  ||
+		tm1.tm_min  != tm2.tm_min  ||
+		tm1.tm_hour != tm2.tm_hour ||
+		tm1.tm_mday != tm2.tm_mday ||
+		tm1.tm_mon  != tm2.tm_mon  ||
+		tm1.tm_year != tm2.tm_year ||
+		tm1.tm_wday != tm2.tm_wday ||
+		tm1.tm_yday != tm2.tm_yday ||
+		tm1.tm_isdst!= tm2.tm_isdst;
+}
+
+char *tm_str(struct tm tm)
+{
+	static int i;
+	static char b[4][64];
+	i = (i+1)%4;
+	snprintf(b[i], sizeof b[i],
+		"s=%.2d m=%.2d h=%.2d mday=%.2d mon=%.2d year=%.4d wday=%d yday=%d isdst=%d",
+		tm.tm_sec, tm.tm_min, tm.tm_hour,
+		tm.tm_mday, tm.tm_mon, tm.tm_year,
+		tm.tm_wday, tm.tm_yday, tm.tm_isdst);
+	return b[i];
+}
+
+#define TM(ss,mm,hh,md,mo,yr,wd,yd,dst) (struct tm){ \
+	.tm_sec = ss, .tm_min = mm, .tm_hour = hh,    \
+	.tm_mday = md, .tm_mon = mo, .tm_year = yr,    \
+	.tm_wday = wd, .tm_yday = yd, .tm_isdst = dst }
+
+#define TM_EPOCH    TM(0,0,0,1,0,70,4,0,0)
+#define TM_Y2038_1S TM(7,14,3,19,0,138,2,18,0)
+#define TM_Y2038    TM(8,14,3,19,0,138,2,18,0)
+
+#define TEST_TM(r,x,m) (!tm_cmp((r),(x)) || \
+(printf(__FILE__ ":%d: %s failed:\n\tresult: %s\n\texpect: %s\n", __LINE__, \
+m, tm_str((r)), tm_str((x))), err++, 0) )
+
+#define TEST(r, f, x, m) ( \
+((r) = (f)) == (x) || \
+(printf(__FILE__ ":%d: %s failed (" m ")\n", __LINE__, #f, r, x), err++, 0) )
+
+int main(void)
+{
+	struct tm tm, *tm_p;
+	time_t t;
+	int err=0;
+
+	putenv("TZ=GMT");
+	tzset();
+
+	t=0; tm_p = gmtime(&t);
+	TEST_TM(*tm_p, TM_EPOCH, "gmtime(0)");
+
+	tm = TM_Y2038_1S;
+	t = mktime(&tm);
+	tm = *(gmtime(&t));
+	TEST_TM(*tm_p, TM_Y2038_1S, "mktime/gmtime(Y2038-1)");
+
+	tm = TM_Y2038;
+	t = mktime(&tm);
+	tm = *(gmtime(&t));
+	TEST_TM(*tm_p, TM_Y2038, "mktime/gmtime(Y2038)");
+
+	/* FIXME: set a TZ var and check DST boundary conditions */
+
+	return err;
+}




More information about the uClibc-cvs mailing list