fix malloc-brk-fail
[libc-test] / src / functional / ipc_msg.c
index 3b91aeb..b243d6d 100644 (file)
 #include "test.h"
 
 static const char path[] = ".";
-static const int id = 'x';
+static const int id = 'm';
 
 #define T(f) do{ \
        if ((f)+1 == 0) \
-               error("%s failed: %s\n", #f, strerror(errno)); \
+               t_error("%s failed: %s\n", #f, strerror(errno)); \
 }while(0)
 
 #define EQ(a,b,fmt) do{ \
        if ((a) != (b)) \
-               error("%s == %s failed: " fmt "\n", #a, #b, a, b); \
+               t_error("%s == %s failed: " fmt "\n", #a, #b, a, b); \
 }while(0)
 
 static void snd()
@@ -43,13 +43,13 @@ static void snd()
        T(msgctl(qid, IPC_RMID, 0));
        T(qid = msgget(k, IPC_CREAT|IPC_EXCL|0666));
 
-       if (test_status)
-               exit(test_status);
+       if (t_status)
+               exit(t_status);
 
        /* check IPC_EXCL */
        errno = 0;
        if (msgget(k, IPC_CREAT|IPC_EXCL|0666) != -1 || errno != EEXIST)
-               error("msgget(IPC_CREAT|IPC_EXCL) should have failed with EEXIST, got %s\n", strerror(errno));
+               t_error("msgget(IPC_CREAT|IPC_EXCL) should have failed with EEXIST, got %s\n", strerror(errno));
 
        /* check if msgget initilaized the msqid_ds structure correctly */
        T(msgctl(qid, IPC_STAT, &qid_ds));
@@ -61,12 +61,14 @@ static void snd()
        EQ(qid_ds.msg_qnum, 0, "got %d, want %d");
        EQ(qid_ds.msg_lspid, 0, "got %d, want %d");
        EQ(qid_ds.msg_lrpid, 0, "got %d, want %d");
-       EQ((long)qid_ds.msg_stime, 0, "got %ld, want %d");
-       EQ((long)qid_ds.msg_rtime, 0, "got %ld, want %d");
+       EQ((long long)qid_ds.msg_stime, 0, "got %lld, want %d");
+       EQ((long long)qid_ds.msg_rtime, 0, "got %lld, want %d");
        if (qid_ds.msg_ctime < t)
-               error("qid_ds.msg_ctime >= t failed: got %ld, want %ld\n", (long)qid_ds.msg_ctime, (long)t);
+               t_error("qid_ds.msg_ctime >= t failed: got %lld, want >= %lld\n", (long long)qid_ds.msg_ctime, (long long)t);
+       if (qid_ds.msg_ctime > t+5)
+               t_error("qid_ds.msg_ctime <= t+5 failed: got %lld, want <= %lld\n", (long long)qid_ds.msg_ctime, (long long)t+5);
        if (qid_ds.msg_qbytes <= 0)
-               error("qid_ds.msg_qbytes > 0 failed: got %d, want 0\n", qid_ds.msg_qbytes, t);
+               t_error("qid_ds.msg_qbytes > 0 failed: got %d, want > 0\n", qid_ds.msg_qbytes, t);
 
        /* test send */
        T(msgsnd(qid, &msg, sizeof msg.data, IPC_NOWAIT));
@@ -74,7 +76,9 @@ static void snd()
        EQ(qid_ds.msg_qnum, 1, "got %d, want %d");
        EQ(qid_ds.msg_lspid, getpid(), "got %d, want %d");
        if (qid_ds.msg_stime < t)
-               error("msg_stime is %ld want >= %ld\n", (long)qid_ds.msg_stime, (long)t);
+               t_error("msg_stime is %lld want >= %lld\n", (long long)qid_ds.msg_stime, (long long)t);
+       if (qid_ds.msg_stime > t+5)
+               t_error("msg_stime is %lld want <= %lld\n", (long long)qid_ds.msg_stime, (long long)t+5);
 }
 
 static void rcv()
@@ -92,16 +96,16 @@ static void rcv()
 
        errno = 0;
        if (msgrcv(qid, &msg, 0, msgtyp, 0) != -1 || errno != E2BIG)
-               error("msgrcv should have failed when msgsize==0 with E2BIG, got %s\n", strerror(errno));
+               t_error("msgrcv should have failed when msgsize==0 with E2BIG, got %s\n", strerror(errno));
 
        /* test receive */
        T(msgrcv(qid, &msg, sizeof msg.data, msgtyp, IPC_NOWAIT));
        if (strcmp(msg.data,"test message") != 0)
-               error("received \"%s\" instead of \"%s\"\n", msg.data, "test message");
+               t_error("received \"%s\" instead of \"%s\"\n", msg.data, "test message");
 
        errno = 0;
        if (msgrcv(qid, &msg, sizeof msg.data, msgtyp, MSG_NOERROR|IPC_NOWAIT) != -1 || errno != ENOMSG)
-               error("msgrcv should have failed when ther is no msg with ENOMSG, got %s\n", strerror(errno));
+               t_error("msgrcv should have failed when ther is no msg with ENOMSG, got %s\n", strerror(errno));
 
        /* cleanup */
        T(msgctl(qid, IPC_RMID, 0));
@@ -115,13 +119,13 @@ int main(void)
        snd();
        p = fork();
        if (p == -1)
-               error("fork failed: %s\n", strerror(errno));
+               t_error("fork failed: %s\n", strerror(errno));
        else if (p == 0)
                rcv();
        else {
                T(waitpid(p, &status, 0));
                if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-                       error("child exit status: %d\n", status);
+                       t_error("child exit status: %d\n", status);
        }
-       return test_status;
+       return t_status;
 }