39
37
#include <upstart/control.h>
45
43
struct sockaddr_un addr;
46
int ret = 0, sock, val;
50
printf ("Testing upstart_open()\n");
48
/* Check that the socket opened is a datagram socket in the
49
* AF_UNIX abstract namespace with a path that includes the PID
50
* of the current process. The SO_PASSCRED option should be set
51
* so that we can get the credentials of any sender.
53
TEST_FUNCTION ("upstart_open");
51
54
sock = upstart_open ();
53
/* Socket should be in AF_UNIX space */
54
56
len = sizeof (addr);
55
assert (getsockname (sock, (struct sockaddr *)&addr, &len) == 0);
56
if (addr.sun_family != AF_UNIX) {
57
printf ("BAD: address family wasn't what we expected.\n");
61
/* Socket should be in abstract namespace */
62
if (addr.sun_path[0] != '\0') {
63
printf ("BAD: address type wasn't what we expected.\n");
67
/* Name should be /com/ubuntu/upstart/$PID */
57
getsockname (sock, (struct sockaddr *)&addr, &len);
59
TEST_EQ (addr.sun_family, AF_UNIX);
60
TEST_EQ (addr.sun_path[0], '\0');
68
62
sprintf (name, "/com/ubuntu/upstart/%d", getpid ());
69
if (strncmp (addr.sun_path + 1, name, strlen (name))) {
70
printf ("BAD: address wasn't what we expected.\n");
74
/* Should work on datagrams */
77
assert (getsockopt (sock, SOL_SOCKET, SO_TYPE, &val, &len) == 0);
78
if (val != SOCK_DGRAM) {
79
printf ("BAD: socket type wasn't what we expected.\n");
83
/* Credentials should be passed with any received message */
86
assert (getsockopt (sock, SOL_SOCKET, SO_PASSCRED, &val, &len) == 0);
88
printf ("BAD: socket will not receive credentials.\n");
63
TEST_EQ_STRN (addr.sun_path + 1, name);
67
getsockopt (sock, SOL_SOCKET, SO_TYPE, &val, &len);
69
TEST_EQ (val, SOCK_DGRAM);
73
getsockopt (sock, SOL_SOCKET, SO_PASSCRED, &val, &len);
99
83
test_send_msg_to (void)
103
int ret = 0, sock, retval;
105
printf ("Testing upstart_send_msg_to()\n");
89
TEST_FUNCTION ("upstart_send_msg_to");
106
90
sock = upstart_open ();
107
91
msg = nih_new (NULL, UpstartMsg);
109
printf ("...with unknown message type\n");
93
/* Check that sending an unknown message type results in the
94
* UPSTART_INVALID_MESSAGE error being raised.
96
TEST_FEATURE ("with unknown message type");
110
97
msg->type = 90210;
111
retval = upstart_send_msg_to (getpid (), sock, msg);
113
/* Return value should be negative */
115
printf ("BAD: return value wasn't what we expected.\n");
119
/* UPSTART_INVALID_MESSAGE should be raised */
98
ret = upstart_send_msg_to (getpid (), sock, msg);
120
102
err = nih_error_get ();
121
if (err->number != UPSTART_INVALID_MESSAGE) {
122
printf ("BAD: raised error wasn't what we expected.\n");
104
TEST_EQ (err->number, UPSTART_INVALID_MESSAGE);
128
printf ("...with overly long message\n");
109
/* Check that sending a message that's too long also results in the
110
* UPSTART_INVALID_MESSAGE error being raised.
112
TEST_FEATURE ("with overly long message");
129
113
msg->type = UPSTART_JOB_QUERY;
130
114
msg->job_query.name = nih_alloc (msg, 8192);
131
115
memset (msg->job_query.name, 'a', 8191);
132
116
msg->job_query.name[8191] = '\0';
134
retval = upstart_send_msg_to (getpid (), sock, msg);
136
/* Return value should be negative */
138
printf ("BAD: return value wasn't what we expected.\n");
142
/* UPSTART_INVALID_MESSAGE should be raised */
118
ret = upstart_send_msg_to (getpid (), sock, msg);
143
122
err = nih_error_get ();
144
if (err->number != UPSTART_INVALID_MESSAGE) {
145
printf ("BAD: raised error wasn't what we expected.\n");
124
TEST_EQ (err->number, UPSTART_INVALID_MESSAGE);
158
134
test_recv_msg (void)
160
136
struct sockaddr_un addr;
228
202
sendto (s_sock, buf, 28, 0, (struct sockaddr *)&addr, addrlen);
229
203
msg = upstart_recv_msg (NULL, r_sock, NULL);
231
/* Return value should be NULL */
233
printf ("BAD: return value wasn't what we expected.\n");
205
TEST_EQ_P (msg, NULL);
237
/* UPSTART_INVALID_MESSAGE should be raised */
238
207
err = nih_error_get ();
239
if (err->number != UPSTART_INVALID_MESSAGE) {
240
printf ("BAD: raised error wasn't what we expected.\n");
209
TEST_EQ (err->number, UPSTART_INVALID_MESSAGE);
246
printf ("...with valid message\n");
214
/* Check that a valid message being received returns that message,
215
* allocated with nih_alloc and with the values filled in. Also
216
* check that the pid of the sender is stored in the argument.
218
TEST_FEATURE ("with valid message");
247
219
memset (buf, 0, 16);
248
220
strncpy (buf, PACKAGE_STRING, 16);
249
221
memcpy (buf + 16, "\0\0\0\0", 4);
250
222
sendto (s_sock, buf, 20, 0, (struct sockaddr *)&addr, addrlen);
251
223
msg = upstart_recv_msg (NULL, r_sock, &pid);
253
/* Message type should be UPSTART_NO_OP */
254
if (msg->type != UPSTART_NO_OP) {
255
printf ("BAD: message type wasn't what we expected.\n");
259
/* Process id should be stored in pid */
260
if (pid != getpid ()) {
261
printf ("BAD: process id wasn't what we expected.\n");
225
TEST_ALLOC_SIZE (msg, sizeof (UpstartMsg));
226
TEST_EQ (msg->type, UPSTART_NO_OP);
227
TEST_EQ (pid, getpid ());
275
237
test_messages (void)
277
239
UpstartMsg *s_msg, *r_msg;
278
240
int s_sock, r_sock;
281
242
/* Rather than test the sending and receiving separately,
282
243
* check whether messages poked in one end come out the other
286
printf ("Testing upstart_send/recv_msg()\n");
247
TEST_FUNCTION ("upstart_send/recv_msg");
287
248
s_sock = socket (PF_UNIX, SOCK_DGRAM, 0);
288
249
r_sock = upstart_open ();
289
250
s_msg = nih_new (NULL, UpstartMsg);
292
printf ("...with UPSTART_NO_OP\n");
253
/* Check that an UPSTART_NO_OP message can be sent and received
254
* correctly, with all fields transmitted properly.
256
TEST_FEATURE ("with UPSTART_NO_OP");
293
257
s_msg->type = UPSTART_NO_OP;
295
259
upstart_send_msg_to (getpid (), s_sock, s_msg);
296
260
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
298
/* Type should be UPSTART_NO_OP */
299
if (r_msg->type != UPSTART_NO_OP) {
300
printf ("BAD: message type wasn't what we expected.\n");
262
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
263
TEST_EQ (r_msg->type, UPSTART_NO_OP);
304
265
nih_free (r_msg);
307
printf ("...with UPSTART_JOB_START\n");
268
/* Check that an UPSTART_JOB_START message can be sent and received
269
* correctly, with all fields transmitted properly.
271
TEST_FEATURE ("with UPSTART_JOB_START");
308
272
s_msg->type = UPSTART_JOB_START;
309
273
s_msg->job_start.name = "wibble";
311
275
upstart_send_msg_to (getpid (), s_sock, s_msg);
312
276
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
314
/* Type should be UPSTART_JOB_START */
315
if (r_msg->type != UPSTART_JOB_START) {
316
printf ("BAD: message type wasn't what we expected.\n");
320
/* Name should be what we sent */
321
if (strcmp (r_msg->job_start.name, "wibble")) {
322
printf ("BAD: job name wasn't what we expected.\n");
326
/* Name should be nih_alloc child of message */
327
if (nih_alloc_parent (r_msg->job_start.name) != r_msg) {
328
printf ("BAD: name wasn't nih_alloc child of message.\n");
278
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
279
TEST_EQ (r_msg->type, UPSTART_JOB_START);
280
TEST_EQ_STR (r_msg->job_start.name, "wibble");
281
TEST_ALLOC_PARENT (r_msg->job_start.name, r_msg);
332
283
nih_free (r_msg);
335
printf ("...with UPSTART_JOB_STOP\n");
286
/* Check that an UPSTART_JOB_STOP message can be sent and received
287
* correctly, with all fields transmitted properly.
289
TEST_FEATURE ("with UPSTART_JOB_STOP");
336
290
s_msg->type = UPSTART_JOB_STOP;
337
291
s_msg->job_stop.name = "wibble";
339
293
upstart_send_msg_to (getpid (), s_sock, s_msg);
340
294
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
342
/* Type should be UPSTART_JOB_STOP */
343
if (r_msg->type != UPSTART_JOB_STOP) {
344
printf ("BAD: message type wasn't what we expected.\n");
348
/* Name should be what we sent */
349
if (strcmp (r_msg->job_stop.name, "wibble")) {
350
printf ("BAD: job name wasn't what we expected.\n");
354
/* Name should be nih_alloc child of message */
355
if (nih_alloc_parent (r_msg->job_stop.name) != r_msg) {
356
printf ("BAD: name wasn't nih_alloc child of message.\n");
296
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
297
TEST_EQ (r_msg->type, UPSTART_JOB_STOP);
298
TEST_EQ_STR (r_msg->job_stop.name, "wibble");
299
TEST_ALLOC_PARENT (r_msg->job_stop.name, r_msg);
360
301
nih_free (r_msg);
363
printf ("...with UPSTART_JOB_QUERY\n");
304
/* Check that an UPSTART_JOB_QUERY message can be sent and received
305
* correctly, with all fields transmitted properly.
307
TEST_FEATURE ("with UPSTART_JOB_QUERY");
364
308
s_msg->type = UPSTART_JOB_QUERY;
365
309
s_msg->job_query.name = "wibble";
367
311
upstart_send_msg_to (getpid (), s_sock, s_msg);
368
312
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
370
/* Type should be UPSTART_JOB_QUERY */
371
if (r_msg->type != UPSTART_JOB_QUERY) {
372
printf ("BAD: message type wasn't what we expected.\n");
376
/* Name should be what we sent */
377
if (strcmp (r_msg->job_query.name, "wibble")) {
378
printf ("BAD: job name wasn't what we expected.\n");
382
/* Name should be nih_alloc child of message */
383
if (nih_alloc_parent (r_msg->job_query.name) != r_msg) {
384
printf ("BAD: name wasn't nih_alloc child of message.\n");
314
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
315
TEST_EQ (r_msg->type, UPSTART_JOB_QUERY);
316
TEST_EQ_STR (r_msg->job_query.name, "wibble");
317
TEST_ALLOC_PARENT (r_msg->job_query.name, r_msg);
388
319
nih_free (r_msg);
391
printf ("...with UPSTART_JOB_STATUS\n");
322
/* Check that an UPSTART_JOB_STATUS message can be sent and received
323
* correctly, with all fields transmitted properly.
325
TEST_FEATURE ("with UPSTART_JOB_STATUS");
392
326
s_msg->type = UPSTART_JOB_STATUS;
393
327
s_msg->job_status.name = "wibble";
394
328
s_msg->job_status.description = "foo bar";
400
334
upstart_send_msg_to (getpid (), s_sock, s_msg);
401
335
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
403
/* Type should be UPSTART_JOB_STATUS */
404
if (r_msg->type != UPSTART_JOB_STATUS) {
405
printf ("BAD: message type wasn't what we expected.\n");
409
/* Name should be what we sent */
410
if (strcmp (r_msg->job_status.name, "wibble")) {
411
printf ("BAD: job name wasn't what we expected.\n");
415
/* Name should be nih_alloc child of message */
416
if (nih_alloc_parent (r_msg->job_status.name) != r_msg) {
417
printf ("BAD: name wasn't nih_alloc child of message.\n");
421
/* Description should be what we sent */
422
if (strcmp (r_msg->job_status.description, "foo bar")) {
423
printf ("BAD: description wasn't what we expected.\n");
427
/* Description should be nih_alloc child of message */
428
if (nih_alloc_parent (r_msg->job_status.description) != r_msg) {
429
printf ("BAD: desc wasn't nih_alloc child of message.\n");
433
/* Job goal should be what we sent */
434
if (r_msg->job_status.goal != JOB_START) {
435
printf ("BAD: job goal wasn't what we expected.\n");
439
/* Job state should be what we sent */
440
if (r_msg->job_status.state != JOB_STARTING) {
441
printf ("BAD: job state wasn't what we expected.\n");
445
/* Process state should be what we sent */
446
if (r_msg->job_status.process_state != PROCESS_ACTIVE) {
447
printf ("BAD: process state wasn't what we expected.\n");
451
/* Process id should be what we sent */
452
if (r_msg->job_status.pid != 123) {
453
printf ("BAD: process id wasn't what we expected.\n");
337
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
338
TEST_EQ (r_msg->type, UPSTART_JOB_STATUS);
339
TEST_EQ_STR (r_msg->job_status.name, "wibble");
340
TEST_ALLOC_PARENT (r_msg->job_status.name, r_msg);
341
TEST_EQ_STR (r_msg->job_status.description, "foo bar");
342
TEST_ALLOC_PARENT (r_msg->job_status.description, r_msg);
343
TEST_EQ (r_msg->job_status.goal, JOB_START);
344
TEST_EQ (r_msg->job_status.state, JOB_STARTING);
345
TEST_EQ (r_msg->job_status.process_state, PROCESS_ACTIVE);
346
TEST_EQ (r_msg->job_status.pid, 123);
457
348
nih_free (r_msg);
460
printf ("...with UPSTART_JOB_STATUS without description\n");
351
/* Check that an UPSTART_JOB_STATUS message without a job
352
* description can be sent and received correctly, with all fields
353
* transmitted properly.
355
TEST_FEATURE ("with UPSTART_JOB_STATUS without description");
461
356
s_msg->job_status.description = NULL;
463
358
upstart_send_msg_to (getpid (), s_sock, s_msg);
464
359
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
466
/* Description should be NULL */
467
if (r_msg->job_status.description != NULL) {
468
printf ("BAD: description wasn't what we expected.\n");
361
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
362
TEST_EQ (r_msg->type, UPSTART_JOB_STATUS);
363
TEST_EQ_STR (r_msg->job_status.name, "wibble");
364
TEST_ALLOC_PARENT (r_msg->job_status.name, r_msg);
365
TEST_EQ_P (r_msg->job_status.description, NULL);
366
TEST_EQ (r_msg->job_status.goal, JOB_START);
367
TEST_EQ (r_msg->job_status.state, JOB_STARTING);
368
TEST_EQ (r_msg->job_status.process_state, PROCESS_ACTIVE);
369
TEST_EQ (r_msg->job_status.pid, 123);
472
371
nih_free (r_msg);
475
printf ("...with UPSTART_JOB_UNKNOWN\n");
374
/* Check that an UPSTART_JOB_UNKNOWN message can be sent and received
375
* correctly, with all fields transmitted properly.
377
TEST_FEATURE ("with UPSTART_JOB_UNKNOWN");
476
378
s_msg->type = UPSTART_JOB_UNKNOWN;
477
379
s_msg->job_unknown.name = "wibble";
479
381
upstart_send_msg_to (getpid (), s_sock, s_msg);
480
382
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
482
/* Type should be UPSTART_JOB_UNKNOWN */
483
if (r_msg->type != UPSTART_JOB_UNKNOWN) {
484
printf ("BAD: message type wasn't what we expected.\n");
488
/* Name should be what we sent */
489
if (strcmp (r_msg->job_unknown.name, "wibble")) {
490
printf ("BAD: job name wasn't what we expected.\n");
494
/* Name should be nih_alloc child of message */
495
if (nih_alloc_parent (r_msg->job_unknown.name) != r_msg) {
496
printf ("BAD: name wasn't nih_alloc child of message.\n");
384
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
385
TEST_EQ (r_msg->type, UPSTART_JOB_UNKNOWN);
386
TEST_EQ_STR (r_msg->job_unknown.name, "wibble");
387
TEST_ALLOC_PARENT (r_msg->job_unknown.name, r_msg);
500
389
nih_free (r_msg);
503
printf ("...with UPSTART_EVENT_QUEUE\n");
392
/* Check that an UPSTART_EVENT_QUEUE message can be sent and received
393
* correctly, with all fields transmitted properly.
395
TEST_FEATURE ("with UPSTART_EVENT_QUEUE");
504
396
s_msg->type = UPSTART_EVENT_QUEUE;
505
397
s_msg->event_queue.name = "frodo";
507
399
upstart_send_msg_to (getpid (), s_sock, s_msg);
508
400
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
510
/* Type should be UPSTART_EVENT_QUEUE */
511
if (r_msg->type != UPSTART_EVENT_QUEUE) {
512
printf ("BAD: message type wasn't what we expected.\n");
516
/* Name should be what we sent */
517
if (strcmp (r_msg->event_queue.name, "frodo")) {
518
printf ("BAD: event name wasn't what we expected.\n");
522
/* Name should be nih_alloc child of message */
523
if (nih_alloc_parent (r_msg->event_queue.name) != r_msg) {
524
printf ("BAD: name wasn't nih_alloc child of message.\n");
402
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
403
TEST_EQ (r_msg->type, UPSTART_EVENT_QUEUE);
404
TEST_EQ_STR (r_msg->event_queue.name, "frodo");
405
TEST_ALLOC_PARENT (r_msg->event_queue.name, r_msg);
528
407
nih_free (r_msg);
531
printf ("...with UPSTART_EVENT\n");
410
/* Check that an UPSTART_EVENT message can be sent and received
411
* correctly, with all fields transmitted properly.
413
TEST_FEATURE ("with UPSTART_EVENT");
532
414
s_msg->type = UPSTART_EVENT;
533
415
s_msg->event.name = "foo";
535
417
upstart_send_msg_to (getpid (), s_sock, s_msg);
536
418
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
538
/* Type should be UPSTART_EVENT */
539
if (r_msg->type != UPSTART_EVENT) {
540
printf ("BAD: message type wasn't what we expected.\n");
544
/* Name should be what we sent */
545
if (strcmp (r_msg->event.name, "foo")) {
546
printf ("BAD: event name wasn't what we expected.\n");
550
/* Name should be nih_alloc child of message */
551
if (nih_alloc_parent (r_msg->event.name) != r_msg) {
552
printf ("BAD: name wasn't nih_alloc child of message.\n");
420
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
421
TEST_EQ (r_msg->type, UPSTART_EVENT);
422
TEST_EQ_STR (r_msg->event.name, "foo");
423
TEST_ALLOC_PARENT (r_msg->event.name, r_msg);
556
425
nih_free (r_msg);
559
printf ("...with UPSTART_JOB_LIST\n");
428
/* Check that an UPSTART_JOB_LIST message can be sent and received
429
* correctly, with all fields transmitted properly.
431
TEST_FEATURE ("with UPSTART_JOB_LIST");
560
432
s_msg->type = UPSTART_JOB_LIST;
562
434
upstart_send_msg_to (getpid (), s_sock, s_msg);
563
435
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
565
/* Type should be UPSTART_JOB_LIST */
566
if (r_msg->type != UPSTART_JOB_LIST) {
567
printf ("BAD: message type wasn't what we expected.\n");
437
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
438
TEST_EQ (r_msg->type, UPSTART_JOB_LIST);
571
440
nih_free (r_msg);
574
printf ("...with UPSTART_JOB_LIST_END\n");
443
/* Check that an UPSTART_JOB_LIST_END message can be sent and received
444
* correctly, with all fields transmitted properly.
446
TEST_FEATURE ("with UPSTART_JOB_LIST_END");
575
447
s_msg->type = UPSTART_JOB_LIST_END;
577
449
upstart_send_msg_to (getpid (), s_sock, s_msg);
578
450
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
580
/* Type should be UPSTART_JOB_LIST_END */
581
if (r_msg->type != UPSTART_JOB_LIST_END) {
582
printf ("BAD: message type wasn't what we expected.\n");
452
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
453
TEST_EQ (r_msg->type, UPSTART_JOB_LIST_END);
586
455
nih_free (r_msg);
589
printf ("...with UPSTART_WATCH_JOBS\n");
458
/* Check that an UPSTART_WATCH_JOBS message can be sent and received
459
* correctly, with all fields transmitted properly.
461
TEST_FEATURE ("with UPSTART_WATCH_JOBS");
590
462
s_msg->type = UPSTART_WATCH_JOBS;
592
464
upstart_send_msg_to (getpid (), s_sock, s_msg);
593
465
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
595
/* Type should be UPSTART_WATCH_JOBS */
596
if (r_msg->type != UPSTART_WATCH_JOBS) {
597
printf ("BAD: message type wasn't what we expected.\n");
467
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
468
TEST_EQ (r_msg->type, UPSTART_WATCH_JOBS);
601
470
nih_free (r_msg);
604
printf ("...with UPSTART_UNWATCH_JOBS\n");
473
/* Check that an UPSTART_UNWATCH_JOBS message can be sent and received
474
* correctly, with all fields transmitted properly.
476
TEST_FEATURE ("with UPSTART_UNWATCH_JOBS");
605
477
s_msg->type = UPSTART_UNWATCH_JOBS;
607
479
upstart_send_msg_to (getpid (), s_sock, s_msg);
608
480
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
610
/* Type should be UPSTART_UNWATCH_JOBS */
611
if (r_msg->type != UPSTART_UNWATCH_JOBS) {
612
printf ("BAD: message type wasn't what we expected.\n");
482
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
483
TEST_EQ (r_msg->type, UPSTART_UNWATCH_JOBS);
616
485
nih_free (r_msg);
619
printf ("...with UPSTART_WATCH_EVENTS\n");
488
/* Check that an UPSTART_WATCH_EVENTS message can be sent and received
489
* correctly, with all fields transmitted properly.
491
TEST_FEATURE ("with UPSTART_WATCH_EVENTS");
620
492
s_msg->type = UPSTART_WATCH_EVENTS;
622
494
upstart_send_msg_to (getpid (), s_sock, s_msg);
623
495
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
625
/* Type should be UPSTART_WATCH_EVENTS */
626
if (r_msg->type != UPSTART_WATCH_EVENTS) {
627
printf ("BAD: message type wasn't what we expected.\n");
497
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
498
TEST_EQ (r_msg->type, UPSTART_WATCH_EVENTS);
631
500
nih_free (r_msg);
634
printf ("...with UPSTART_UNWATCH_EVENTS\n");
503
/* Check that an UPSTART_UNWATCH_EVENTS message can be sent and
504
* received correctly, with all fields transmitted properly.
506
TEST_FEATURE ("with UPSTART_UNWATCH_EVENTS");
635
507
s_msg->type = UPSTART_UNWATCH_EVENTS;
637
509
upstart_send_msg_to (getpid (), s_sock, s_msg);
638
510
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
640
/* Type should be UPSTART_UNWATCH_EVENTS */
641
if (r_msg->type != UPSTART_UNWATCH_EVENTS) {
642
printf ("BAD: message type wasn't what we expected.\n");
512
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
513
TEST_EQ (r_msg->type, UPSTART_UNWATCH_EVENTS);
646
515
nih_free (r_msg);
649
printf ("...with UPSTART_SHUTDOWN\n");
518
/* Check that an UPSTART_SHUTDOWN message can be sent and received
519
* correctly, with all fields transmitted properly.
521
TEST_FEATURE ("with UPSTART_SHUTDOWN");
650
522
s_msg->type = UPSTART_SHUTDOWN;
651
523
s_msg->shutdown.name = "reboot";
653
525
upstart_send_msg_to (getpid (), s_sock, s_msg);
654
526
r_msg = upstart_recv_msg (NULL, r_sock, NULL);
656
/* Type should be UPSTART_SHUTDOWN */
657
if (r_msg->type != UPSTART_SHUTDOWN) {
658
printf ("BAD: message type wasn't what we expected.\n");
662
/* Name should be what we sent */
663
if (strcmp (r_msg->shutdown.name, "reboot")) {
664
printf ("BAD: event name wasn't what we expected.\n");
668
/* Name should be nih_alloc child of message */
669
if (nih_alloc_parent (r_msg->event_queue.name) != r_msg) {
670
printf ("BAD: name wasn't nih_alloc child of message.\n");
528
TEST_ALLOC_SIZE (r_msg, sizeof (UpstartMsg));
529
TEST_EQ (r_msg->type, UPSTART_SHUTDOWN);
530
TEST_EQ_STR (r_msg->shutdown.name, "reboot");
531
TEST_ALLOC_PARENT (r_msg->shutdown.name, r_msg);
674
533
nih_free (r_msg);
676
536
nih_free (s_msg);
690
printf ("Testing upstart_free()\n");
691
ptr = nih_alloc (NULL, 1024);
694
/* didn't crash, so it worked */