X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Ffunctional%2Fipc_msg.c;h=9752a44440cb90813e29995d375a1f6fff40a97c;hb=0b44f33283ddf8911f47a14ac4d015755af4405b;hp=3b91aebefba685bac2e44333d74967c11172485a;hpb=2cf89517c5b25c2524fe0c0c01ed277d7307a852;p=libc-test diff --git a/src/functional/ipc_msg.c b/src/functional/ipc_msg.c index 3b91aeb..9752a44 100644 --- a/src/functional/ipc_msg.c +++ b/src/functional/ipc_msg.c @@ -12,16 +12,16 @@ #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)); @@ -64,9 +64,11 @@ static void snd() EQ((long)qid_ds.msg_stime, 0, "got %ld, want %d"); EQ((long)qid_ds.msg_rtime, 0, "got %ld, 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 %ld, want >= %ld\n", (long)qid_ds.msg_ctime, (long)t); + if (qid_ds.msg_ctime > t+5) + t_error("qid_ds.msg_ctime <= t+5 failed: got %ld, want <= %ld\n", (long)qid_ds.msg_ctime, (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 %ld want >= %ld\n", (long)qid_ds.msg_stime, (long)t); + if (qid_ds.msg_stime > t+5) + t_error("msg_stime is %ld want <= %ld\n", (long)qid_ds.msg_stime, (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; }