#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()
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));
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));
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()
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));
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;
}