471
test_stanza_apparmor (void)
479
TEST_FUNCTION ("stanza_apparmor");
482
/* Check that an apparmor load stanza sets the process of the
483
* job as a single string.
485
TEST_FEATURE ("with load and profile");
486
strcpy (buf, "apparmor load /etc/apparmor.d/usr.sbin.cupsd\n");
488
/* TODO: investigate why we can't use TEST_ALLOC_FAIL here.
489
* It fails when nih_sprintf() is used.
494
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
497
TEST_EQ (pos, strlen (buf));
500
TEST_ALLOC_SIZE (job, sizeof (JobClass));
502
process = job->process[PROCESS_SECURITY];
503
TEST_ALLOC_PARENT (process, job->process);
504
TEST_ALLOC_SIZE (process, sizeof (Process));
505
TEST_EQ (process->script, FALSE);
506
TEST_ALLOC_PARENT (process->command, process);
507
strcpy (buf, APPARMOR_PARSER);
509
strcat (buf, APPARMOR_PARSER_OPTS);
510
strcat (buf, " /etc/apparmor.d/usr.sbin.cupsd");
511
TEST_EQ_STR (process->command, buf);
516
/* Check that the last of multiple apparmor load stanzas is used. */
517
TEST_FEATURE ("with multiple load");
518
strcpy (buf, "apparmor load /etc/apparmor.d/usr.sbin.rsyslogd\n");
519
strcat (buf, "apparmor load /etc/apparmor.d/usr.sbin.cupsd\n");
521
/* TODO: investigate why we can't use TEST_ALLOC_FAIL here.
522
* It fails when nih_sprintf() is used.
527
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
530
TEST_EQ (pos, strlen (buf));
533
TEST_ALLOC_SIZE (job, sizeof (JobClass));
535
process = job->process[PROCESS_SECURITY];
536
TEST_ALLOC_PARENT (process, job->process);
537
TEST_ALLOC_SIZE (process, sizeof (Process));
538
TEST_EQ (process->script, FALSE);
539
TEST_ALLOC_PARENT (process->command, process);
540
strcpy (buf, APPARMOR_PARSER);
542
strcat (buf, APPARMOR_PARSER_OPTS);
543
strcat (buf, " /etc/apparmor.d/usr.sbin.cupsd");
544
TEST_EQ_STR (process->command, buf);
549
/* Check that an apparmor load stanza without any arguments results
552
TEST_FEATURE ("with load but no profile");
553
strcpy (buf, "apparmor load\n");
557
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
559
TEST_EQ_P (job, NULL);
561
err = nih_error_get ();
562
TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
568
/* Check that an apparmor load stanza with an extra argument
569
* results in a syntax error.
571
TEST_FEATURE ("with extra argument to load");
572
strcpy (buf, "apparmor load /etc/apparmor.d/usr.sbin.cupsd extra\n");
576
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
578
TEST_EQ_P (job, NULL);
580
err = nih_error_get ();
581
TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
587
/* Check that an apparmor stanza with an unknown second argument
588
* results in a syntax error.
590
TEST_FEATURE ("with unknown argument");
591
strcpy (buf, "apparmor foo\n");
595
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
597
TEST_EQ_P (job, NULL);
599
err = nih_error_get ();
600
TEST_EQ (err->number, NIH_CONFIG_UNKNOWN_STANZA);
606
/* Check that an apparmor stanza with no second argument
607
* results in a syntax error.
609
TEST_FEATURE ("with missing argument");
610
strcpy (buf, "apparmor\n");
614
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
616
TEST_EQ_P (job, NULL);
618
err = nih_error_get ();
619
TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
625
/* Check that an apparmor switch stanza results in it
626
* being stored in the job.
628
TEST_FEATURE ("with switch and profile");
629
strcpy (buf, "apparmor switch /usr/sbin/cupsd\n");
634
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
637
if (test_alloc_failed) {
638
TEST_EQ_P (job, NULL);
640
err = nih_error_get ();
641
TEST_EQ (err->number, ENOMEM);
647
TEST_EQ (pos, strlen (buf));
650
TEST_ALLOC_SIZE (job, sizeof (JobClass));
652
TEST_ALLOC_PARENT (job->apparmor_switch, job);
653
TEST_EQ_STR (job->apparmor_switch, "/usr/sbin/cupsd");
659
/* Check that the last of multiple apparmor switch stanzas is used. */
660
TEST_FEATURE ("with multiple apparmor switch stanzas");
661
strcpy (buf, "apparmor switch /usr/sbin/rsyslogd\n");
662
strcat (buf, "apparmor switch /usr/sbin/cupsd\n");
667
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
670
if (test_alloc_failed) {
671
TEST_EQ_P (job, NULL);
673
err = nih_error_get ();
674
TEST_EQ (err->number, ENOMEM);
680
TEST_EQ (pos, strlen (buf));
683
TEST_ALLOC_SIZE (job, sizeof (JobClass));
685
TEST_ALLOC_PARENT (job->apparmor_switch, job);
686
TEST_EQ_STR (job->apparmor_switch, "/usr/sbin/cupsd");
692
/* Check that an apparmor switch stanza without a profile results in
695
TEST_FEATURE ("with switch and no profile");
696
strcpy (buf, "apparmor switch\n");
700
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
702
TEST_EQ_P (job, NULL);
704
err = nih_error_get ();
705
TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
711
/* Check that an apparmor switch stanza with an extra second argument
712
* results in a syntax error.
714
TEST_FEATURE ("with extra argument to switch");
715
strcpy (buf, "apparmor switch /usr/sbin/cupsd extra\n");
719
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
721
TEST_EQ_P (job, NULL);
723
err = nih_error_get ();
724
TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
732
431
test_stanza_pre_start (void)
2833
test_stanza_manual (void)
2839
EventOperator *oper;
2841
TEST_FUNCTION ("stanza_manual");
2843
/* manual only ignores *previously specified* start on
2846
TEST_FEATURE ("manual_stanza before start on");
2847
strcpy (buf, "manual\nstart on wibble\n");
2849
/* ensure we haven't broken a basic start on event by introducing the
2850
* manual stanza into a config
2855
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
2858
if (test_alloc_failed) {
2859
TEST_EQ_P (job, NULL);
2861
err = nih_error_get ();
2862
TEST_EQ (err->number, ENOMEM);
2868
TEST_EQ (lineno, 3);
2870
TEST_ALLOC_SIZE (job, sizeof (JobClass));
2872
TEST_ALLOC_SIZE (job->start_on, sizeof (EventOperator));
2873
TEST_ALLOC_PARENT (job->start_on, job);
2875
oper = job->start_on;
2876
TEST_EQ (oper->type, EVENT_MATCH);
2877
TEST_EQ_STR (oper->name, "wibble");
2878
TEST_EQ_P (oper->env, NULL);
2880
TEST_EQ_P (oper->node.parent, NULL);
2881
TEST_EQ_P (oper->node.left, NULL);
2882
TEST_EQ_P (oper->node.right, NULL);
2887
TEST_FEATURE ("manual stanza after start on");
2888
strcpy (buf, "start on wibble\nmanual\n");
2890
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
2893
TEST_NE_P (job, NULL);
2894
TEST_ALLOC_SIZE (job, sizeof (JobClass));
2895
TEST_EQ_P (job->start_on, NULL);
2901
2532
test_stanza_stop (void)
5103
/* Check that a kill stanza with the signal argument and signal,
5104
* sets the right signal on the jobs class.
5106
TEST_FEATURE ("with signal and single argument");
5107
strcpy (buf, "kill signal INT\n");
5112
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
5115
if (test_alloc_failed) {
5116
TEST_EQ_P (job, NULL);
5118
err = nih_error_get ();
5119
TEST_EQ (err->number, ENOMEM);
5125
TEST_EQ (pos, strlen (buf));
5126
TEST_EQ (lineno, 2);
5128
TEST_ALLOC_SIZE (job, sizeof (JobClass));
5130
TEST_EQ (job->kill_signal, SIGINT);
5135
/* Check that a kill stanza with the signal argument and numeric signal,
5136
* sets the right signal on the jobs class.
5138
TEST_FEATURE ("with signal and single numeric argument");
5139
strcpy (buf, "kill signal 30\n");
5144
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
5147
if (test_alloc_failed) {
5148
TEST_EQ_P (job, NULL);
5150
err = nih_error_get ();
5151
TEST_EQ (err->number, ENOMEM);
5157
TEST_EQ (pos, strlen (buf));
5158
TEST_EQ (lineno, 2);
5160
TEST_ALLOC_SIZE (job, sizeof (JobClass));
5162
/* Don't check symbolic here since different
5163
* architectures have different mappings.
5165
TEST_EQ (job->kill_signal, 30);
5170
4734
/* Check that the last of multiple kill stanzas is used.
5172
4736
TEST_FEATURE ("with multiple timeout and single argument stanzas");
5210
test_stanza_session (void)
5217
TEST_FUNCTION ("stanza_session");
5219
/* Check that session leader sets the job's to be a session leader.
5221
TEST_FEATURE ("with leader argument");
5222
strcpy (buf, "session leader\n");
5227
job = parse_job (NULL, "test", buf, strlen (buf),
5230
if (test_alloc_failed) {
5231
TEST_EQ_P (job, NULL);
5233
err = nih_error_get ();
5234
TEST_EQ (err->number, ENOMEM);
5240
TEST_EQ (pos, strlen (buf));
5241
TEST_EQ (lineno, 2);
5243
TEST_ALLOC_SIZE (job, sizeof (JobClass));
5245
TEST_EQ (job->console, CONSOLE_NONE);
5251
/* Check that multiple stanzas are ok.
5253
TEST_FEATURE ("with multiple stanzas");
5254
strcpy (buf, "session leader\n");
5255
strcat (buf, "session leader\n");
5260
job = parse_job (NULL, "test", buf, strlen (buf),
5263
if (test_alloc_failed) {
5264
TEST_EQ_P (job, NULL);
5266
err = nih_error_get ();
5267
TEST_EQ (err->number, ENOMEM);
5273
TEST_EQ (pos, strlen (buf));
5274
TEST_EQ (lineno, 3);
5276
TEST_ALLOC_SIZE (job, sizeof (JobClass));
5278
TEST_EQ (job->leader, TRUE);
5284
/* Check that an unknown argument raises a syntax error.
5286
TEST_FEATURE ("with unknown argument");
5287
strcpy (buf, "session wibble\n");
5291
job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5293
TEST_EQ_P (job, NULL);
5295
err = nih_error_get ();
5296
TEST_EQ (err->number, NIH_CONFIG_UNKNOWN_STANZA);
5298
TEST_EQ (lineno, 1);
5302
/* Check that additional arguments to the stanza results in
5305
TEST_FEATURE ("with argument");
5306
strcpy (buf, "session leader foo\n");
5310
job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5312
TEST_EQ_P (job, NULL);
5314
err = nih_error_get ();
5315
TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
5317
TEST_EQ (lineno, 1);
5321
/* Check that a missing argument raises a syntax error.
5323
TEST_FEATURE ("with missing argument");
5324
strcpy (buf, "session\n");
5328
job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5330
TEST_EQ_P (job, NULL);
5332
err = nih_error_get ();
5333
TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
5335
TEST_EQ (lineno, 1);
5735
5340
test_stanza_console (void)
6671
6242
TEST_ALLOC_FAIL {
6674
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6677
if (test_alloc_failed) {
6678
TEST_EQ_P (job, NULL);
6680
err = nih_error_get ();
6681
TEST_EQ (err->number, ENOMEM);
6687
TEST_EQ (pos, strlen (buf));
6688
TEST_EQ (lineno, 2);
6690
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6692
TEST_EQ (job->oom_score_adj, ADJ_TO_SCORE(10));
6697
TEST_FEATURE ("with positive score argument");
6698
strcpy (buf, "oom score 100\n");
6703
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6706
if (test_alloc_failed) {
6707
TEST_EQ_P (job, NULL);
6709
err = nih_error_get ();
6710
TEST_EQ (err->number, ENOMEM);
6716
TEST_EQ (pos, strlen (buf));
6717
TEST_EQ (lineno, 2);
6719
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6721
TEST_EQ (job->oom_score_adj, 100);
6245
job = parse_job (NULL, "test", buf, strlen (buf),
6248
if (test_alloc_failed) {
6249
TEST_EQ_P (job, NULL);
6251
err = nih_error_get ();
6252
TEST_EQ (err->number, ENOMEM);
6258
TEST_EQ (pos, strlen (buf));
6259
TEST_EQ (lineno, 2);
6261
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6263
TEST_EQ (job->oom_adj, 10);
6726
6269
/* Check that an oom stanza with a negative timeout results
6727
6270
* in it being stored in the job.
6732
6275
TEST_ALLOC_FAIL {
6735
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6738
if (test_alloc_failed) {
6739
TEST_EQ_P (job, NULL);
6741
err = nih_error_get ();
6742
TEST_EQ (err->number, ENOMEM);
6748
TEST_EQ (pos, strlen (buf));
6749
TEST_EQ (lineno, 2);
6751
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6753
TEST_EQ (job->oom_score_adj, ADJ_TO_SCORE(-10));
6758
TEST_FEATURE ("with negative score argument");
6759
strcpy (buf, "oom score -100\n");
6764
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6767
if (test_alloc_failed) {
6768
TEST_EQ_P (job, NULL);
6770
err = nih_error_get ();
6771
TEST_EQ (err->number, ENOMEM);
6777
TEST_EQ (pos, strlen (buf));
6778
TEST_EQ (lineno, 2);
6780
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6782
TEST_EQ (job->oom_score_adj, -100);
6278
job = parse_job (NULL, "test", buf, strlen (buf),
6281
if (test_alloc_failed) {
6282
TEST_EQ_P (job, NULL);
6284
err = nih_error_get ();
6285
TEST_EQ (err->number, ENOMEM);
6291
TEST_EQ (pos, strlen (buf));
6292
TEST_EQ (lineno, 2);
6294
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6296
TEST_EQ (job->oom_adj, -10);
6784
6298
nih_free (job);
6794
6308
TEST_ALLOC_FAIL {
6797
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6800
if (test_alloc_failed) {
6801
TEST_EQ_P (job, NULL);
6803
err = nih_error_get ();
6804
TEST_EQ (err->number, ENOMEM);
6810
TEST_EQ (pos, strlen (buf));
6811
TEST_EQ (lineno, 2);
6813
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6815
TEST_EQ (job->oom_score_adj, ADJ_TO_SCORE(-17));
6821
/* Check that an oom score stanza may have the special never
6822
* argument which stores -1000 in the job.
6824
TEST_FEATURE ("with never score argument");
6825
strcpy (buf, "oom score never\n");
6830
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6833
if (test_alloc_failed) {
6834
TEST_EQ_P (job, NULL);
6836
err = nih_error_get ();
6837
TEST_EQ (err->number, ENOMEM);
6843
TEST_EQ (pos, strlen (buf));
6844
TEST_EQ (lineno, 2);
6846
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6848
TEST_EQ (job->oom_score_adj, -1000);
6311
job = parse_job (NULL, "test", buf, strlen (buf),
6314
if (test_alloc_failed) {
6315
TEST_EQ_P (job, NULL);
6317
err = nih_error_get ();
6318
TEST_EQ (err->number, ENOMEM);
6324
TEST_EQ (pos, strlen (buf));
6325
TEST_EQ (lineno, 2);
6327
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6329
TEST_EQ (job->oom_adj, -17);
6850
6331
nih_free (job);
6860
6341
TEST_ALLOC_FAIL {
6863
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6866
if (test_alloc_failed) {
6867
TEST_EQ_P (job, NULL);
6869
err = nih_error_get ();
6870
TEST_EQ (err->number, ENOMEM);
6876
TEST_EQ (pos, strlen (buf));
6877
TEST_EQ (lineno, 3);
6879
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6881
TEST_EQ (job->oom_score_adj, ADJ_TO_SCORE(10));
6886
TEST_FEATURE ("with multiple score stanzas");
6887
strcpy (buf, "oom score -500\n");
6888
strcat (buf, "oom score 500\n");
6893
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6896
if (test_alloc_failed) {
6897
TEST_EQ_P (job, NULL);
6899
err = nih_error_get ();
6900
TEST_EQ (err->number, ENOMEM);
6906
TEST_EQ (pos, strlen (buf));
6907
TEST_EQ (lineno, 3);
6909
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6911
TEST_EQ (job->oom_score_adj, 500);
6916
/* Check that the last of multiple distinct oom stanzas is
6919
TEST_FEATURE ("with an oom overriding an oom score stanza");
6920
strcpy (buf, "oom score -10\n");
6921
strcat (buf, "oom 10\n");
6926
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6929
if (test_alloc_failed) {
6930
TEST_EQ_P (job, NULL);
6932
err = nih_error_get ();
6933
TEST_EQ (err->number, ENOMEM);
6939
TEST_EQ (pos, strlen (buf));
6940
TEST_EQ (lineno, 3);
6942
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6944
TEST_EQ (job->oom_score_adj, ADJ_TO_SCORE(10));
6949
TEST_FEATURE ("with an oom score overriding an oom stanza");
6950
strcpy (buf, "oom -10\n");
6951
strcat (buf, "oom score 10\n");
6956
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6959
if (test_alloc_failed) {
6960
TEST_EQ_P (job, NULL);
6962
err = nih_error_get ();
6963
TEST_EQ (err->number, ENOMEM);
6969
TEST_EQ (pos, strlen (buf));
6970
TEST_EQ (lineno, 3);
6972
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6974
TEST_EQ (job->oom_score_adj, 10);
6344
job = parse_job (NULL, "test", buf, strlen (buf),
6347
if (test_alloc_failed) {
6348
TEST_EQ_P (job, NULL);
6350
err = nih_error_get ();
6351
TEST_EQ (err->number, ENOMEM);
6357
TEST_EQ (pos, strlen (buf));
6358
TEST_EQ (lineno, 3);
6360
TEST_ALLOC_SIZE (job, sizeof (JobClass));
6362
TEST_EQ (job->oom_adj, 10);
6976
6364
nih_free (job);
8261
7555
nih_free (err);
8265
test_stanza_setuid (void)
8272
TEST_FUNCTION ("stanza_setuid");
8274
/* Check that a setuid stanza with an argument results in it
8275
* being stored in the job.
8277
TEST_FEATURE ("with single argument");
8278
strcpy (buf, "setuid www-data\n");
8283
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
8286
if (test_alloc_failed) {
8287
TEST_EQ_P (job, NULL);
8289
err = nih_error_get ();
8290
TEST_EQ (err->number, ENOMEM);
8296
TEST_EQ (pos, strlen (buf));
8297
TEST_EQ (lineno, 2);
8299
TEST_ALLOC_SIZE (job, sizeof (JobClass));
8301
TEST_ALLOC_PARENT (job->setuid, job);
8302
TEST_EQ_STR (job->setuid, "www-data");
8308
/* Check that the last of multiple setuid stanzas is used.
8310
TEST_FEATURE ("with multiple stanzas");
8311
strcpy (buf, "setuid www-data\n");
8312
strcat (buf, "setuid pulse\n");
8317
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
8320
if (test_alloc_failed) {
8321
TEST_EQ_P (job, NULL);
8323
err = nih_error_get ();
8324
TEST_EQ (err->number, ENOMEM);
8330
TEST_EQ (pos, strlen (buf));
8331
TEST_EQ (lineno, 3);
8333
TEST_ALLOC_SIZE (job, sizeof (JobClass));
8335
TEST_ALLOC_PARENT (job->setuid, job);
8336
TEST_EQ_STR (job->setuid, "pulse");
8342
/* Check that a setuid stanza without an argument results in
8345
TEST_FEATURE ("with missing argument");
8346
strcpy (buf, "setuid\n");
8350
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
8352
TEST_EQ_P (job, NULL);
8354
err = nih_error_get ();
8355
TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
8357
TEST_EQ (lineno, 1);
8361
/* Check that a setuid stanza with an extra second argument
8362
* results in a syntax error.
8364
TEST_FEATURE ("with extra argument");
8365
strcpy (buf, "setuid www-data foo\n");
8369
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
8371
TEST_EQ_P (job, NULL);
8373
err = nih_error_get ();
8374
TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
8376
TEST_EQ (lineno, 1);
8381
test_stanza_setgid (void)
8388
TEST_FUNCTION ("stanza_setgid");
8390
/* Check that a setgid stanza with an argument results in it
8391
* being stored in the job.
8393
TEST_FEATURE ("with single argument");
8394
strcpy (buf, "setgid kvm\n");
8399
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
8402
if (test_alloc_failed) {
8403
TEST_EQ_P (job, NULL);
8405
err = nih_error_get ();
8406
TEST_EQ (err->number, ENOMEM);
8412
TEST_EQ (pos, strlen (buf));
8413
TEST_EQ (lineno, 2);
8415
TEST_ALLOC_SIZE (job, sizeof (JobClass));
8417
TEST_ALLOC_PARENT (job->setgid, job);
8418
TEST_EQ_STR (job->setgid, "kvm");
8424
/* Check that the last of multiple setgid stanzas is used.
8426
TEST_FEATURE ("with multiple stanzas");
8427
strcpy (buf, "setgid kvm\n");
8428
strcat (buf, "setgid fuse\n");
8433
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
8436
if (test_alloc_failed) {
8437
TEST_EQ_P (job, NULL);
8439
err = nih_error_get ();
8440
TEST_EQ (err->number, ENOMEM);
8446
TEST_EQ (pos, strlen (buf));
8447
TEST_EQ (lineno, 3);
8449
TEST_ALLOC_SIZE (job, sizeof (JobClass));
8451
TEST_ALLOC_PARENT (job->setgid, job);
8452
TEST_EQ_STR (job->setgid, "fuse");
8458
/* Check that a setgid stanza without an argument results in
8461
TEST_FEATURE ("with missing argument");
8462
strcpy (buf, "setgid\n");
8466
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
8468
TEST_EQ_P (job, NULL);
8470
err = nih_error_get ();
8471
TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
8473
TEST_EQ (lineno, 1);
8477
/* Check that a setgid stanza with an extra second argument
8478
* results in a syntax error.
8480
TEST_FEATURE ("with extra argument");
8481
strcpy (buf, "setgid kvm foo\n");
8485
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
8487
TEST_EQ_P (job, NULL);
8489
err = nih_error_get ();
8490
TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
8492
TEST_EQ (lineno, 1);
8497
test_stanza_usage (void)
8504
TEST_FUNCTION ("stanza_usage");
8506
/* Check that a usage stanza with an argument results in it
8507
* being stored in the job.
8509
TEST_FEATURE ("with single argument");
8510
strcpy (buf, "usage \"stanza usage test message\"\n");
8515
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
8518
if (test_alloc_failed) {
8519
TEST_EQ_P (job, NULL);
8521
err = nih_error_get ();
8522
TEST_EQ (err->number, ENOMEM);
8528
TEST_EQ (pos, strlen (buf));
8529
TEST_EQ (lineno, 2);
8531
TEST_ALLOC_SIZE (job, sizeof (JobClass));
8533
TEST_ALLOC_PARENT (job->usage, job);
8534
TEST_EQ_STR (job->usage, "stanza usage test message");
8540
/* Check that the last of multiple usage stanzas is used.
8542
TEST_FEATURE ("with multiple stanzas");
8543
strcpy (buf, "usage \"stanza usage original\"\n");
8544
strcat (buf, "usage \"stanza usage test message\"\n");
8549
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
8552
if (test_alloc_failed) {
8553
TEST_EQ_P (job, NULL);
8555
err = nih_error_get ();
8556
TEST_EQ (err->number, ENOMEM);
8562
TEST_EQ (pos, strlen (buf));
8563
TEST_EQ (lineno, 3);
8565
TEST_ALLOC_SIZE (job, sizeof (JobClass));
8567
TEST_ALLOC_PARENT (job->usage, job);
8568
TEST_EQ_STR (job->usage, "stanza usage test message");
8574
/* Check that a usage stanza without an argument results in
8577
TEST_FEATURE ("with missing argument");
8578
strcpy (buf, "usage\n");
8582
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
8584
TEST_EQ_P (job, NULL);
8586
err = nih_error_get ();
8587
TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
8589
TEST_EQ (lineno, 1);
8593
/* Check that a usage stanza with an extra second argument
8594
* results in a syntax error.
8596
TEST_FEATURE ("with extra argument");
8597
strcpy (buf, "usage stanza usage test message\n");
8601
job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
8603
TEST_EQ_P (job, NULL);
8605
err = nih_error_get ();
8606
TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
8608
TEST_EQ (lineno, 1);
8613
7559
main (int argc,
8616
/* run tests in legacy (pre-session support) mode */
8617
setenv ("UPSTART_NO_SESSIONS", "1", 1);
8619
7562
test_parse_job ();
8621
7564
test_stanza_instance ();