~jamesodhunt/upstart/test-quiesce-cleanup

« back to all changes in this revision

Viewing changes to init/tests/test_parse_job.c

  • Committer: Scott James Remnant
  • Date: 2009-07-08 19:43:16 UTC
  • Revision ID: scott@netsplit.com-20090708194316-t6rw4e8auuza6qju
* conf/control-alt-delete.conf: Default job for Control-Alt-Delete
* conf/rc-sysinit.conf: Default job for system initialisation
* conf/rc.conf: A fully wacky instance job that runs the rc script
for runlevel changes
* conf/rcS.conf: And a job for single-user-mode, which calls back
to rc-sysinit
* conf/Makefile.am (dist_init_DATA): Install the default files
into the /etc/init directory
* configure.ac (AC_CONFIG_FILES): Create conf/Makefile
* Makefile.am (SUBDIRS): Recurse into the conf directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *
3
3
 * test_parse_job.c - test suite for init/parse_job.c
4
4
 *
5
 
 * Copyright © 2010 Canonical Ltd.
 
5
 * Copyright © 2009 Canonical Ltd.
6
6
 * Author: Scott James Remnant <scott@netsplit.com>.
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
36
36
#include "conf.h"
37
37
#include "parse_job.h"
38
38
#include "errors.h"
39
 
#include "apparmor.h"
40
39
 
41
40
 
42
41
void
65
64
        TEST_ALLOC_FAIL {
66
65
                pos = 0;
67
66
                lineno = 1;
68
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
67
                job = parse_job (NULL, "test", buf, strlen (buf),
69
68
                                 &pos, &lineno);
70
69
 
71
70
                if (test_alloc_failed) {
111
110
        TEST_ALLOC_FAIL {
112
111
                pos = 0;
113
112
                lineno = 1;
114
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
113
                job = parse_job (NULL, "test", buf, strlen (buf),
115
114
                                 &pos, &lineno);
116
115
 
117
116
                if (test_alloc_failed) {
132
131
 
133
132
                nih_free (job);
134
133
        }
135
 
 
136
 
        TEST_FEATURE ("with non-NULL update parameter (override)");
137
 
        {
138
 
                JobClass *tmp = NULL;
139
 
 
140
 
                strcpy (buf, "start on starting\n");
141
 
                strcat (buf, "author \"me\"\n");
142
 
 
143
 
                pos = 0;
144
 
                lineno = 1;
145
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
146
 
                                &pos, &lineno);
147
 
 
148
 
                TEST_NE_P (job, NULL);
149
 
                TEST_EQ_STR (job->author, "me");
150
 
                TEST_NE_P (job->start_on, NULL);
151
 
 
152
 
                strcat (buf, "author \"you\"\n");
153
 
                strcat (buf, "manual\n");
154
 
                strcat (buf, "description \"my description\"\n");
155
 
 
156
 
                pos = 0;
157
 
                lineno = 1;
158
 
                tmp = parse_job (NULL, NULL, job, "test", buf, strlen (buf),
159
 
                                &pos, &lineno);
160
 
                TEST_NE_P (tmp, NULL);
161
 
 
162
 
                /* if passed a job, the same object should be returned.
163
 
                 */
164
 
                TEST_EQ_P (tmp, job);
165
 
 
166
 
                TEST_EQ_STR (tmp->author, "you");
167
 
                TEST_EQ_P (tmp->start_on, NULL);
168
 
                TEST_NE_P (tmp->description, NULL);
169
 
 
170
 
                TEST_EQ_STR (tmp->description, "my description");
171
 
 
172
 
                nih_free (job);
173
 
        }
174
134
}
175
135
 
176
136
void
193
153
        TEST_ALLOC_FAIL {
194
154
                pos = 0;
195
155
                lineno = 1;
196
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
156
                job = parse_job (NULL, "test", buf, strlen (buf),
197
157
                                 &pos, &lineno);
198
158
 
199
159
                if (test_alloc_failed) {
230
190
        TEST_ALLOC_FAIL {
231
191
                pos = 0;
232
192
                lineno = 1;
233
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
193
                job = parse_job (NULL, "test", buf, strlen (buf),
234
194
                                 &pos, &lineno);
235
195
 
236
196
                if (test_alloc_failed) {
269
229
        TEST_ALLOC_FAIL {
270
230
                pos = 0;
271
231
                lineno = 1;
272
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
232
                job = parse_job (NULL, "test", buf, strlen (buf),
273
233
                                 &pos, &lineno);
274
234
 
275
235
                if (test_alloc_failed) {
306
266
 
307
267
        pos = 0;
308
268
        lineno = 1;
309
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
269
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
310
270
 
311
271
        TEST_EQ_P (job, NULL);
312
272
 
339
299
        TEST_ALLOC_FAIL {
340
300
                pos = 0;
341
301
                lineno = 1;
342
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
302
                job = parse_job (NULL, "test", buf, strlen (buf),
343
303
                                 &pos, &lineno);
344
304
 
345
305
                if (test_alloc_failed) {
380
340
        TEST_ALLOC_FAIL {
381
341
                pos = 0;
382
342
                lineno = 1;
383
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
343
                job = parse_job (NULL, "test", buf, strlen (buf),
384
344
                                 &pos, &lineno);
385
345
 
386
346
                if (test_alloc_failed) {
419
379
        TEST_ALLOC_FAIL {
420
380
                pos = 0;
421
381
                lineno = 1;
422
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
382
                job = parse_job (NULL, "test", buf, strlen (buf),
423
383
                                 &pos, &lineno);
424
384
 
425
385
                if (test_alloc_failed) {
456
416
 
457
417
        pos = 0;
458
418
        lineno = 1;
459
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
419
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
460
420
 
461
421
        TEST_EQ_P (job, NULL);
462
422
 
468
428
}
469
429
 
470
430
void
471
 
test_stanza_apparmor (void)
472
 
{
473
 
        JobClass *job;
474
 
        Process  *process;
475
 
        NihError *err;
476
 
        size_t    pos, lineno;
477
 
        char      buf[1024];
478
 
 
479
 
        TEST_FUNCTION ("stanza_apparmor");
480
 
 
481
 
 
482
 
        /* Check that an apparmor load stanza sets the process of the
483
 
         * job as a single string.
484
 
         */
485
 
        TEST_FEATURE ("with load and profile");
486
 
        strcpy (buf, "apparmor load /etc/apparmor.d/usr.sbin.cupsd\n");
487
 
 
488
 
        /* TODO: investigate why we can't use TEST_ALLOC_FAIL here.
489
 
         * It fails when nih_sprintf() is used.
490
 
         */
491
 
 
492
 
        pos = 0;
493
 
        lineno = 1;
494
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
495
 
                         &pos, &lineno);
496
 
 
497
 
        TEST_EQ (pos, strlen (buf));
498
 
        TEST_EQ (lineno, 2);
499
 
 
500
 
        TEST_ALLOC_SIZE (job, sizeof (JobClass));
501
 
 
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);
508
 
        strcat (buf, " ");
509
 
        strcat (buf, APPARMOR_PARSER_OPTS);
510
 
        strcat (buf, " /etc/apparmor.d/usr.sbin.cupsd");
511
 
        TEST_EQ_STR (process->command, buf);
512
 
 
513
 
        nih_free (job);
514
 
 
515
 
 
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");
520
 
 
521
 
        /* TODO: investigate why we can't use TEST_ALLOC_FAIL here.
522
 
         * It fails when nih_sprintf() is used.
523
 
         */
524
 
 
525
 
        pos = 0;
526
 
        lineno = 1;
527
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
528
 
                         &pos, &lineno);
529
 
 
530
 
        TEST_EQ (pos, strlen (buf));
531
 
        TEST_EQ (lineno, 3);
532
 
 
533
 
        TEST_ALLOC_SIZE (job, sizeof (JobClass));
534
 
 
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);
541
 
        strcat (buf, " ");
542
 
        strcat (buf, APPARMOR_PARSER_OPTS);
543
 
        strcat (buf, " /etc/apparmor.d/usr.sbin.cupsd");
544
 
        TEST_EQ_STR (process->command, buf);
545
 
 
546
 
        nih_free (job);
547
 
 
548
 
 
549
 
        /* Check that an apparmor load stanza without any arguments results
550
 
         * in a syntax error.
551
 
         */
552
 
        TEST_FEATURE ("with load but no profile");
553
 
        strcpy (buf, "apparmor load\n");
554
 
 
555
 
        pos = 0;
556
 
        lineno = 1;
557
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
558
 
 
559
 
        TEST_EQ_P (job, NULL);
560
 
 
561
 
        err = nih_error_get ();
562
 
        TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
563
 
        TEST_EQ (pos, 13);
564
 
        TEST_EQ (lineno, 1);
565
 
        nih_free (err);
566
 
 
567
 
 
568
 
        /* Check that an apparmor load stanza with an extra argument
569
 
         * results in a syntax error.
570
 
         */
571
 
        TEST_FEATURE ("with extra argument to load");
572
 
        strcpy (buf, "apparmor load /etc/apparmor.d/usr.sbin.cupsd extra\n");
573
 
 
574
 
        pos = 0;
575
 
        lineno = 1;
576
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
577
 
 
578
 
        TEST_EQ_P (job, NULL);
579
 
 
580
 
        err = nih_error_get ();
581
 
        TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
582
 
        TEST_EQ (pos, 45);
583
 
        TEST_EQ (lineno, 1);
584
 
        nih_free (err);
585
 
 
586
 
 
587
 
        /* Check that an apparmor stanza with an unknown second argument
588
 
         * results in a syntax error.
589
 
         */
590
 
        TEST_FEATURE ("with unknown argument");
591
 
        strcpy (buf, "apparmor foo\n");
592
 
 
593
 
        pos = 0;
594
 
        lineno = 1;
595
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
596
 
 
597
 
        TEST_EQ_P (job, NULL);
598
 
 
599
 
        err = nih_error_get ();
600
 
        TEST_EQ (err->number, NIH_CONFIG_UNKNOWN_STANZA);
601
 
        TEST_EQ (pos, 9);
602
 
        TEST_EQ (lineno, 1);
603
 
        nih_free (err);
604
 
 
605
 
 
606
 
        /* Check that an apparmor stanza with no second argument
607
 
         * results in a syntax error.
608
 
         */
609
 
        TEST_FEATURE ("with missing argument");
610
 
        strcpy (buf, "apparmor\n");
611
 
 
612
 
        pos = 0;
613
 
        lineno = 1;
614
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
615
 
 
616
 
        TEST_EQ_P (job, NULL);
617
 
 
618
 
        err = nih_error_get ();
619
 
        TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
620
 
        TEST_EQ (pos, 8);
621
 
        TEST_EQ (lineno, 1);
622
 
        nih_free (err);
623
 
 
624
 
 
625
 
        /* Check that an apparmor switch stanza results in it
626
 
         * being stored in the job.
627
 
         */
628
 
        TEST_FEATURE ("with switch and profile");
629
 
        strcpy (buf, "apparmor switch /usr/sbin/cupsd\n");
630
 
 
631
 
        TEST_ALLOC_FAIL {
632
 
                pos = 0;
633
 
                lineno = 1;
634
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
635
 
                                 &pos, &lineno);
636
 
 
637
 
                if (test_alloc_failed) {
638
 
                        TEST_EQ_P (job, NULL);
639
 
 
640
 
                        err = nih_error_get ();
641
 
                        TEST_EQ (err->number, ENOMEM);
642
 
                        nih_free (err);
643
 
 
644
 
                        continue;
645
 
                }
646
 
 
647
 
                TEST_EQ (pos, strlen (buf));
648
 
                TEST_EQ (lineno, 2);
649
 
 
650
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
651
 
 
652
 
                TEST_ALLOC_PARENT (job->apparmor_switch, job);
653
 
                TEST_EQ_STR (job->apparmor_switch, "/usr/sbin/cupsd");
654
 
 
655
 
                nih_free (job);
656
 
        }
657
 
 
658
 
 
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");
663
 
 
664
 
        TEST_ALLOC_FAIL {
665
 
                pos = 0;
666
 
                lineno = 1;
667
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
668
 
                                 &pos, &lineno);
669
 
 
670
 
                if (test_alloc_failed) {
671
 
                        TEST_EQ_P (job, NULL);
672
 
 
673
 
                        err = nih_error_get ();
674
 
                        TEST_EQ (err->number, ENOMEM);
675
 
                        nih_free (err);
676
 
 
677
 
                        continue;
678
 
                }
679
 
 
680
 
                TEST_EQ (pos, strlen (buf));
681
 
                TEST_EQ (lineno, 3);
682
 
 
683
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
684
 
 
685
 
                TEST_ALLOC_PARENT (job->apparmor_switch, job);
686
 
                TEST_EQ_STR (job->apparmor_switch, "/usr/sbin/cupsd");
687
 
 
688
 
                nih_free (job);
689
 
        }
690
 
 
691
 
 
692
 
        /* Check that an apparmor switch stanza without a profile results in
693
 
         * a syntax error.
694
 
         */
695
 
        TEST_FEATURE ("with switch and no profile");
696
 
        strcpy (buf, "apparmor switch\n");
697
 
 
698
 
        pos = 0;
699
 
        lineno = 1;
700
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
701
 
 
702
 
        TEST_EQ_P (job, NULL);
703
 
 
704
 
        err = nih_error_get ();
705
 
        TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
706
 
        TEST_EQ (pos, 15);
707
 
        TEST_EQ (lineno, 1);
708
 
        nih_free (err);
709
 
 
710
 
 
711
 
        /* Check that an apparmor switch stanza with an extra second argument
712
 
         * results in a syntax error.
713
 
         */
714
 
        TEST_FEATURE ("with extra argument to switch");
715
 
        strcpy (buf, "apparmor switch /usr/sbin/cupsd extra\n");
716
 
 
717
 
        pos = 0;
718
 
        lineno = 1;
719
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
720
 
 
721
 
        TEST_EQ_P (job, NULL);
722
 
 
723
 
        err = nih_error_get ();
724
 
        TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
725
 
        TEST_EQ (pos, 32);
726
 
        TEST_EQ (lineno, 1);
727
 
        nih_free (err);
728
 
 
729
 
}
730
 
 
731
 
void
732
431
test_stanza_pre_start (void)
733
432
{
734
433
        JobClass *job;
748
447
        TEST_ALLOC_FAIL {
749
448
                pos = 0;
750
449
                lineno = 1;
751
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
450
                job = parse_job (NULL, "test", buf, strlen (buf),
752
451
                                 &pos, &lineno);
753
452
 
754
453
                if (test_alloc_failed) {
785
484
        TEST_ALLOC_FAIL {
786
485
                pos = 0;
787
486
                lineno = 1;
788
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
487
                job = parse_job (NULL, "test", buf, strlen (buf),
789
488
                                 &pos, &lineno);
790
489
 
791
490
                if (test_alloc_failed) {
825
524
        TEST_ALLOC_FAIL {
826
525
                pos = 0;
827
526
                lineno = 1;
828
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
527
                job = parse_job (NULL, "test", buf, strlen (buf),
829
528
                                 &pos, &lineno);
830
529
 
831
530
                if (test_alloc_failed) {
866
565
        TEST_ALLOC_FAIL {
867
566
                pos = 0;
868
567
                lineno = 1;
869
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
568
                job = parse_job (NULL, "test", buf, strlen (buf),
870
569
                                 &pos, &lineno);
871
570
 
872
571
                if (test_alloc_failed) {
905
604
        TEST_ALLOC_FAIL {
906
605
                pos = 0;
907
606
                lineno = 1;
908
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
607
                job = parse_job (NULL, "test", buf, strlen (buf),
909
608
                                 &pos, &lineno);
910
609
 
911
610
                if (test_alloc_failed) {
944
643
        TEST_ALLOC_FAIL {
945
644
                pos = 0;
946
645
                lineno = 1;
947
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
646
                job = parse_job (NULL, "test", buf, strlen (buf),
948
647
                                 &pos, &lineno);
949
648
 
950
649
                if (test_alloc_failed) {
981
680
 
982
681
        pos = 0;
983
682
        lineno = 1;
984
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
683
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
985
684
 
986
685
        TEST_EQ_P (job, NULL);
987
686
 
1000
699
 
1001
700
        pos = 0;
1002
701
        lineno = 1;
1003
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
702
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1004
703
 
1005
704
        TEST_EQ_P (job, NULL);
1006
705
 
1019
718
 
1020
719
        pos = 0;
1021
720
        lineno = 1;
1022
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
721
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1023
722
 
1024
723
        TEST_EQ_P (job, NULL);
1025
724
 
1038
737
 
1039
738
        pos = 0;
1040
739
        lineno = 1;
1041
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
740
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1042
741
 
1043
742
        TEST_EQ_P (job, NULL);
1044
743
 
1069
768
        TEST_ALLOC_FAIL {
1070
769
                pos = 0;
1071
770
                lineno = 1;
1072
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
771
                job = parse_job (NULL, "test", buf, strlen (buf),
1073
772
                                 &pos, &lineno);
1074
773
 
1075
774
                if (test_alloc_failed) {
1106
805
        TEST_ALLOC_FAIL {
1107
806
                pos = 0;
1108
807
                lineno = 1;
1109
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
808
                job = parse_job (NULL, "test", buf, strlen (buf),
1110
809
                                 &pos, &lineno);
1111
810
 
1112
811
                if (test_alloc_failed) {
1146
845
        TEST_ALLOC_FAIL {
1147
846
                pos = 0;
1148
847
                lineno = 1;
1149
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
848
                job = parse_job (NULL, "test", buf, strlen (buf),
1150
849
                                 &pos, &lineno);
1151
850
 
1152
851
                if (test_alloc_failed) {
1187
886
        TEST_ALLOC_FAIL {
1188
887
                pos = 0;
1189
888
                lineno = 1;
1190
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
889
                job = parse_job (NULL, "test", buf, strlen (buf),
1191
890
                                 &pos, &lineno);
1192
891
 
1193
892
                if (test_alloc_failed) {
1226
925
        TEST_ALLOC_FAIL {
1227
926
                pos = 0;
1228
927
                lineno = 1;
1229
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
928
                job = parse_job (NULL, "test", buf, strlen (buf),
1230
929
                                 &pos, &lineno);
1231
930
 
1232
931
                if (test_alloc_failed) {
1265
964
        TEST_ALLOC_FAIL {
1266
965
                pos = 0;
1267
966
                lineno = 1;
1268
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
967
                job = parse_job (NULL, "test", buf, strlen (buf),
1269
968
                                 &pos, &lineno);
1270
969
 
1271
970
                if (test_alloc_failed) {
1302
1001
 
1303
1002
        pos = 0;
1304
1003
        lineno = 1;
1305
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
1004
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1306
1005
 
1307
1006
        TEST_EQ_P (job, NULL);
1308
1007
 
1321
1020
 
1322
1021
        pos = 0;
1323
1022
        lineno = 1;
1324
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
1023
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1325
1024
 
1326
1025
        TEST_EQ_P (job, NULL);
1327
1026
 
1340
1039
 
1341
1040
        pos = 0;
1342
1041
        lineno = 1;
1343
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
1042
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1344
1043
 
1345
1044
        TEST_EQ_P (job, NULL);
1346
1045
 
1359
1058
 
1360
1059
        pos = 0;
1361
1060
        lineno = 1;
1362
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
1061
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1363
1062
 
1364
1063
        TEST_EQ_P (job, NULL);
1365
1064
 
1390
1089
        TEST_ALLOC_FAIL {
1391
1090
                pos = 0;
1392
1091
                lineno = 1;
1393
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1092
                job = parse_job (NULL, "test", buf, strlen (buf),
1394
1093
                                 &pos, &lineno);
1395
1094
 
1396
1095
                if (test_alloc_failed) {
1427
1126
        TEST_ALLOC_FAIL {
1428
1127
                pos = 0;
1429
1128
                lineno = 1;
1430
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1129
                job = parse_job (NULL, "test", buf, strlen (buf),
1431
1130
                                 &pos, &lineno);
1432
1131
 
1433
1132
                if (test_alloc_failed) {
1467
1166
        TEST_ALLOC_FAIL {
1468
1167
                pos = 0;
1469
1168
                lineno = 1;
1470
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1169
                job = parse_job (NULL, "test", buf, strlen (buf),
1471
1170
                                 &pos, &lineno);
1472
1171
 
1473
1172
                if (test_alloc_failed) {
1508
1207
        TEST_ALLOC_FAIL {
1509
1208
                pos = 0;
1510
1209
                lineno = 1;
1511
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1210
                job = parse_job (NULL, "test", buf, strlen (buf),
1512
1211
                                 &pos, &lineno);
1513
1212
 
1514
1213
                if (test_alloc_failed) {
1547
1246
        TEST_ALLOC_FAIL {
1548
1247
                pos = 0;
1549
1248
                lineno = 1;
1550
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1249
                job = parse_job (NULL, "test", buf, strlen (buf),
1551
1250
                                 &pos, &lineno);
1552
1251
 
1553
1252
                if (test_alloc_failed) {
1586
1285
        TEST_ALLOC_FAIL {
1587
1286
                pos = 0;
1588
1287
                lineno = 1;
1589
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1288
                job = parse_job (NULL, "test", buf, strlen (buf),
1590
1289
                                 &pos, &lineno);
1591
1290
 
1592
1291
                if (test_alloc_failed) {
1623
1322
 
1624
1323
        pos = 0;
1625
1324
        lineno = 1;
1626
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
1325
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1627
1326
 
1628
1327
        TEST_EQ_P (job, NULL);
1629
1328
 
1642
1341
 
1643
1342
        pos = 0;
1644
1343
        lineno = 1;
1645
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
1344
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1646
1345
 
1647
1346
        TEST_EQ_P (job, NULL);
1648
1347
 
1661
1360
 
1662
1361
        pos = 0;
1663
1362
        lineno = 1;
1664
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
1363
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1665
1364
 
1666
1365
        TEST_EQ_P (job, NULL);
1667
1366
 
1680
1379
 
1681
1380
        pos = 0;
1682
1381
        lineno = 1;
1683
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
1382
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1684
1383
 
1685
1384
        TEST_EQ_P (job, NULL);
1686
1385
 
1711
1410
        TEST_ALLOC_FAIL {
1712
1411
                pos = 0;
1713
1412
                lineno = 1;
1714
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1413
                job = parse_job (NULL, "test", buf, strlen (buf),
1715
1414
                                 &pos, &lineno);
1716
1415
 
1717
1416
                if (test_alloc_failed) {
1748
1447
        TEST_ALLOC_FAIL {
1749
1448
                pos = 0;
1750
1449
                lineno = 1;
1751
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1450
                job = parse_job (NULL, "test", buf, strlen (buf),
1752
1451
                                 &pos, &lineno);
1753
1452
 
1754
1453
                if (test_alloc_failed) {
1788
1487
        TEST_ALLOC_FAIL {
1789
1488
                pos = 0;
1790
1489
                lineno = 1;
1791
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1490
                job = parse_job (NULL, "test", buf, strlen (buf),
1792
1491
                                 &pos, &lineno);
1793
1492
 
1794
1493
                if (test_alloc_failed) {
1829
1528
        TEST_ALLOC_FAIL {
1830
1529
                pos = 0;
1831
1530
                lineno = 1;
1832
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1531
                job = parse_job (NULL, "test", buf, strlen (buf),
1833
1532
                                 &pos, &lineno);
1834
1533
 
1835
1534
                if (test_alloc_failed) {
1868
1567
        TEST_ALLOC_FAIL {
1869
1568
                pos = 0;
1870
1569
                lineno = 1;
1871
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1570
                job = parse_job (NULL, "test", buf, strlen (buf),
1872
1571
                                 &pos, &lineno);
1873
1572
 
1874
1573
                if (test_alloc_failed) {
1907
1606
        TEST_ALLOC_FAIL {
1908
1607
                pos = 0;
1909
1608
                lineno = 1;
1910
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1609
                job = parse_job (NULL, "test", buf, strlen (buf),
1911
1610
                                 &pos, &lineno);
1912
1611
 
1913
1612
                if (test_alloc_failed) {
1944
1643
 
1945
1644
        pos = 0;
1946
1645
        lineno = 1;
1947
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
1646
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1948
1647
 
1949
1648
        TEST_EQ_P (job, NULL);
1950
1649
 
1963
1662
 
1964
1663
        pos = 0;
1965
1664
        lineno = 1;
1966
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
1665
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1967
1666
 
1968
1667
        TEST_EQ_P (job, NULL);
1969
1668
 
1982
1681
 
1983
1682
        pos = 0;
1984
1683
        lineno = 1;
1985
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
1684
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
1986
1685
 
1987
1686
        TEST_EQ_P (job, NULL);
1988
1687
 
2001
1700
 
2002
1701
        pos = 0;
2003
1702
        lineno = 1;
2004
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
1703
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2005
1704
 
2006
1705
        TEST_EQ_P (job, NULL);
2007
1706
 
2032
1731
        TEST_ALLOC_FAIL {
2033
1732
                pos = 0;
2034
1733
                lineno = 1;
2035
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1734
                job = parse_job (NULL, "test", buf, strlen (buf),
2036
1735
                                 &pos, &lineno);
2037
1736
 
2038
1737
                if (test_alloc_failed) {
2077
1776
        TEST_ALLOC_FAIL {
2078
1777
                pos = 0;
2079
1778
                lineno = 1;
2080
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1779
                job = parse_job (NULL, "test", buf, strlen (buf),
2081
1780
                                 &pos, &lineno);
2082
1781
 
2083
1782
                if (test_alloc_failed) {
2129
1828
        TEST_ALLOC_FAIL {
2130
1829
                pos = 0;
2131
1830
                lineno = 1;
2132
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1831
                job = parse_job (NULL, "test", buf, strlen (buf),
2133
1832
                                 &pos, &lineno);
2134
1833
 
2135
1834
                if (test_alloc_failed) {
2180
1879
        TEST_ALLOC_FAIL {
2181
1880
                pos = 0;
2182
1881
                lineno = 1;
2183
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1882
                job = parse_job (NULL, "test", buf, strlen (buf),
2184
1883
                                 &pos, &lineno);
2185
1884
 
2186
1885
                if (test_alloc_failed) {
2243
1942
        TEST_ALLOC_FAIL {
2244
1943
                pos = 0;
2245
1944
                lineno = 1;
2246
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
1945
                job = parse_job (NULL, "test", buf, strlen (buf),
2247
1946
                                 &pos, &lineno);
2248
1947
 
2249
1948
                if (test_alloc_failed) {
2313
2012
        TEST_ALLOC_FAIL {
2314
2013
                pos = 0;
2315
2014
                lineno = 1;
2316
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
2015
                job = parse_job (NULL, "test", buf, strlen (buf),
2317
2016
                                 &pos, &lineno);
2318
2017
 
2319
2018
                if (test_alloc_failed) {
2391
2090
        TEST_ALLOC_FAIL {
2392
2091
                pos = 0;
2393
2092
                lineno = 1;
2394
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
2093
                job = parse_job (NULL, "test", buf, strlen (buf),
2395
2094
                                 &pos, &lineno);
2396
2095
 
2397
2096
                if (test_alloc_failed) {
2471
2170
        TEST_ALLOC_FAIL {
2472
2171
                pos = 0;
2473
2172
                lineno = 1;
2474
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
2173
                job = parse_job (NULL, "test", buf, strlen (buf),
2475
2174
                                 &pos, &lineno);
2476
2175
 
2477
2176
                if (test_alloc_failed) {
2550
2249
        TEST_ALLOC_FAIL {
2551
2250
                pos = 0;
2552
2251
                lineno = 1;
2553
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
2252
                job = parse_job (NULL, "test", buf, strlen (buf),
2554
2253
                                 &pos, &lineno);
2555
2254
 
2556
2255
                if (test_alloc_failed) {
2592
2291
 
2593
2292
        pos = 0;
2594
2293
        lineno = 1;
2595
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2294
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2596
2295
 
2597
2296
        TEST_EQ_P (job, NULL);
2598
2297
 
2611
2310
 
2612
2311
        pos = 0;
2613
2312
        lineno = 1;
2614
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2313
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2615
2314
 
2616
2315
        TEST_EQ_P (job, NULL);
2617
2316
 
2630
2329
 
2631
2330
        pos = 0;
2632
2331
        lineno = 1;
2633
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2332
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2634
2333
 
2635
2334
        TEST_EQ_P (job, NULL);
2636
2335
 
2649
2348
 
2650
2349
        pos = 0;
2651
2350
        lineno = 1;
2652
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2351
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2653
2352
 
2654
2353
        TEST_EQ_P (job, NULL);
2655
2354
 
2668
2367
 
2669
2368
        pos = 0;
2670
2369
        lineno = 1;
2671
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2370
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2672
2371
 
2673
2372
        TEST_EQ_P (job, NULL);
2674
2373
 
2685
2384
 
2686
2385
        pos = 0;
2687
2386
        lineno = 1;
2688
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2387
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2689
2388
 
2690
2389
        TEST_EQ_P (job, NULL);
2691
2390
 
2704
2403
 
2705
2404
        pos = 0;
2706
2405
        lineno = 1;
2707
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2406
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2708
2407
 
2709
2408
        TEST_EQ_P (job, NULL);
2710
2409
 
2723
2422
 
2724
2423
        pos = 0;
2725
2424
        lineno = 1;
2726
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2425
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2727
2426
 
2728
2427
        TEST_EQ_P (job, NULL);
2729
2428
 
2742
2441
 
2743
2442
        pos = 0;
2744
2443
        lineno = 1;
2745
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2444
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2746
2445
 
2747
2446
        TEST_EQ_P (job, NULL);
2748
2447
 
2761
2460
 
2762
2461
        pos = 0;
2763
2462
        lineno = 1;
2764
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2463
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2765
2464
 
2766
2465
        TEST_EQ_P (job, NULL);
2767
2466
 
2780
2479
 
2781
2480
        pos = 0;
2782
2481
        lineno = 1;
2783
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2482
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2784
2483
 
2785
2484
        TEST_EQ_P (job, NULL);
2786
2485
 
2799
2498
 
2800
2499
        pos = 0;
2801
2500
        lineno = 1;
2802
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2501
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2803
2502
 
2804
2503
        TEST_EQ_P (job, NULL);
2805
2504
 
2818
2517
 
2819
2518
        pos = 0;
2820
2519
        lineno = 1;
2821
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
2520
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
2822
2521
 
2823
2522
        TEST_EQ_P (job, NULL);
2824
2523
 
2830
2529
}
2831
2530
 
2832
2531
void
2833
 
test_stanza_manual (void)
2834
 
{
2835
 
        char           buf[1024];
2836
 
        size_t         pos, lineno;
2837
 
        JobClass      *job;
2838
 
        NihError      *err;
2839
 
        EventOperator *oper;
2840
 
 
2841
 
        TEST_FUNCTION ("stanza_manual");
2842
 
 
2843
 
        /* manual only ignores *previously specified* start on
2844
 
         * events.
2845
 
         */
2846
 
        TEST_FEATURE ("manual_stanza before start on");
2847
 
        strcpy (buf, "manual\nstart on wibble\n");
2848
 
 
2849
 
        /* ensure we haven't broken a basic start on event by introducing the
2850
 
         * manual stanza into a config
2851
 
         */
2852
 
        TEST_ALLOC_FAIL {
2853
 
                pos = 0;
2854
 
                lineno = 1;
2855
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
2856
 
                                 &pos, &lineno);
2857
 
 
2858
 
                if (test_alloc_failed) {
2859
 
                        TEST_EQ_P (job, NULL);
2860
 
 
2861
 
                        err = nih_error_get ();
2862
 
                        TEST_EQ (err->number, ENOMEM);
2863
 
                        nih_free (err);
2864
 
 
2865
 
                        continue;
2866
 
                }
2867
 
 
2868
 
                TEST_EQ (lineno, 3);
2869
 
 
2870
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
2871
 
 
2872
 
                TEST_ALLOC_SIZE (job->start_on, sizeof (EventOperator));
2873
 
                TEST_ALLOC_PARENT (job->start_on, job);
2874
 
 
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);
2879
 
 
2880
 
                TEST_EQ_P (oper->node.parent, NULL);
2881
 
                TEST_EQ_P (oper->node.left, NULL);
2882
 
                TEST_EQ_P (oper->node.right, NULL);
2883
 
 
2884
 
                nih_free (job);
2885
 
        }
2886
 
 
2887
 
        TEST_FEATURE ("manual stanza after start on");
2888
 
        strcpy (buf, "start on wibble\nmanual\n");
2889
 
 
2890
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
2891
 
                        &pos, &lineno);
2892
 
 
2893
 
        TEST_NE_P (job, NULL);
2894
 
        TEST_ALLOC_SIZE (job, sizeof (JobClass));
2895
 
        TEST_EQ_P (job->start_on, NULL);
2896
 
 
2897
 
        nih_free (job);
2898
 
}
2899
 
 
2900
 
void
2901
2532
test_stanza_stop (void)
2902
2533
{
2903
2534
        JobClass     *job;
2917
2548
        TEST_ALLOC_FAIL {
2918
2549
                pos = 0;
2919
2550
                lineno = 1;
2920
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
2551
                job = parse_job (NULL, "test", buf, strlen (buf),
2921
2552
                                 &pos, &lineno);
2922
2553
 
2923
2554
                if (test_alloc_failed) {
2962
2593
        TEST_ALLOC_FAIL {
2963
2594
                pos = 0;
2964
2595
                lineno = 1;
2965
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
2596
                job = parse_job (NULL, "test", buf, strlen (buf),
2966
2597
                                 &pos, &lineno);
2967
2598
 
2968
2599
                if (test_alloc_failed) {
3014
2645
        TEST_ALLOC_FAIL {
3015
2646
                pos = 0;
3016
2647
                lineno = 1;
3017
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
2648
                job = parse_job (NULL, "test", buf, strlen (buf),
3018
2649
                                 &pos, &lineno);
3019
2650
 
3020
2651
                if (test_alloc_failed) {
3065
2696
        TEST_ALLOC_FAIL {
3066
2697
                pos = 0;
3067
2698
                lineno = 1;
3068
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
2699
                job = parse_job (NULL, "test", buf, strlen (buf),
3069
2700
                                 &pos, &lineno);
3070
2701
 
3071
2702
                if (test_alloc_failed) {
3128
2759
        TEST_ALLOC_FAIL {
3129
2760
                pos = 0;
3130
2761
                lineno = 1;
3131
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
2762
                job = parse_job (NULL, "test", buf, strlen (buf),
3132
2763
                                 &pos, &lineno);
3133
2764
 
3134
2765
                if (test_alloc_failed) {
3198
2829
        TEST_ALLOC_FAIL {
3199
2830
                pos = 0;
3200
2831
                lineno = 1;
3201
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
2832
                job = parse_job (NULL, "test", buf, strlen (buf),
3202
2833
                                 &pos, &lineno);
3203
2834
 
3204
2835
                if (test_alloc_failed) {
3276
2907
        TEST_ALLOC_FAIL {
3277
2908
                pos = 0;
3278
2909
                lineno = 1;
3279
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
2910
                job = parse_job (NULL, "test", buf, strlen (buf),
3280
2911
                                 &pos, &lineno);
3281
2912
 
3282
2913
                if (test_alloc_failed) {
3356
2987
        TEST_ALLOC_FAIL {
3357
2988
                pos = 0;
3358
2989
                lineno = 1;
3359
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
2990
                job = parse_job (NULL, "test", buf, strlen (buf),
3360
2991
                                 &pos, &lineno);
3361
2992
 
3362
2993
                if (test_alloc_failed) {
3435
3066
        TEST_ALLOC_FAIL {
3436
3067
                pos = 0;
3437
3068
                lineno = 1;
3438
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3069
                job = parse_job (NULL, "test", buf, strlen (buf),
3439
3070
                                 &pos, &lineno);
3440
3071
 
3441
3072
                if (test_alloc_failed) {
3477
3108
 
3478
3109
        pos = 0;
3479
3110
        lineno = 1;
3480
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3111
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3481
3112
 
3482
3113
        TEST_EQ_P (job, NULL);
3483
3114
 
3496
3127
 
3497
3128
        pos = 0;
3498
3129
        lineno = 1;
3499
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3130
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3500
3131
 
3501
3132
        TEST_EQ_P (job, NULL);
3502
3133
 
3515
3146
 
3516
3147
        pos = 0;
3517
3148
        lineno = 1;
3518
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3149
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3519
3150
 
3520
3151
        TEST_EQ_P (job, NULL);
3521
3152
 
3534
3165
 
3535
3166
        pos = 0;
3536
3167
        lineno = 1;
3537
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3168
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3538
3169
 
3539
3170
        TEST_EQ_P (job, NULL);
3540
3171
 
3553
3184
 
3554
3185
        pos = 0;
3555
3186
        lineno = 1;
3556
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3187
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3557
3188
 
3558
3189
        TEST_EQ_P (job, NULL);
3559
3190
 
3570
3201
 
3571
3202
        pos = 0;
3572
3203
        lineno = 1;
3573
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3204
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3574
3205
 
3575
3206
        TEST_EQ_P (job, NULL);
3576
3207
 
3589
3220
 
3590
3221
        pos = 0;
3591
3222
        lineno = 1;
3592
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3223
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3593
3224
 
3594
3225
        TEST_EQ_P (job, NULL);
3595
3226
 
3608
3239
 
3609
3240
        pos = 0;
3610
3241
        lineno = 1;
3611
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3242
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3612
3243
 
3613
3244
        TEST_EQ_P (job, NULL);
3614
3245
 
3627
3258
 
3628
3259
        pos = 0;
3629
3260
        lineno = 1;
3630
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3261
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3631
3262
 
3632
3263
        TEST_EQ_P (job, NULL);
3633
3264
 
3646
3277
 
3647
3278
        pos = 0;
3648
3279
        lineno = 1;
3649
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3280
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3650
3281
 
3651
3282
        TEST_EQ_P (job, NULL);
3652
3283
 
3665
3296
 
3666
3297
        pos = 0;
3667
3298
        lineno = 1;
3668
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3299
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3669
3300
 
3670
3301
        TEST_EQ_P (job, NULL);
3671
3302
 
3684
3315
 
3685
3316
        pos = 0;
3686
3317
        lineno = 1;
3687
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3318
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3688
3319
 
3689
3320
        TEST_EQ_P (job, NULL);
3690
3321
 
3703
3334
 
3704
3335
        pos = 0;
3705
3336
        lineno = 1;
3706
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3337
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3707
3338
 
3708
3339
        TEST_EQ_P (job, NULL);
3709
3340
 
3733
3364
        TEST_ALLOC_FAIL {
3734
3365
                pos = 0;
3735
3366
                lineno = 1;
3736
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3367
                job = parse_job (NULL, "test", buf, strlen (buf),
3737
3368
                                 &pos, &lineno);
3738
3369
 
3739
3370
                if (test_alloc_failed) {
3766
3397
        TEST_ALLOC_FAIL {
3767
3398
                pos = 0;
3768
3399
                lineno = 1;
3769
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3400
                job = parse_job (NULL, "test", buf, strlen (buf),
3770
3401
                                 &pos, &lineno);
3771
3402
 
3772
3403
                if (test_alloc_failed) {
3799
3430
 
3800
3431
        pos = 0;
3801
3432
        lineno = 1;
3802
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3433
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3803
3434
 
3804
3435
        TEST_EQ_P (job, NULL);
3805
3436
 
3818
3449
 
3819
3450
        pos = 0;
3820
3451
        lineno = 1;
3821
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3452
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3822
3453
 
3823
3454
        TEST_EQ_P (job, NULL);
3824
3455
 
3848
3479
        TEST_ALLOC_FAIL {
3849
3480
                pos = 0;
3850
3481
                lineno = 1;
3851
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3482
                job = parse_job (NULL, "test", buf, strlen (buf),
3852
3483
                                 &pos, &lineno);
3853
3484
 
3854
3485
                if (test_alloc_failed) {
3881
3512
        TEST_ALLOC_FAIL {
3882
3513
                pos = 0;
3883
3514
                lineno = 1;
3884
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3515
                job = parse_job (NULL, "test", buf, strlen (buf),
3885
3516
                                 &pos, &lineno);
3886
3517
 
3887
3518
                if (test_alloc_failed) {
3914
3545
 
3915
3546
        pos = 0;
3916
3547
        lineno = 1;
3917
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3548
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3918
3549
 
3919
3550
        TEST_EQ_P (job, NULL);
3920
3551
 
3933
3564
 
3934
3565
        pos = 0;
3935
3566
        lineno = 1;
3936
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3567
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
3937
3568
 
3938
3569
        TEST_EQ_P (job, NULL);
3939
3570
 
3963
3594
        TEST_ALLOC_FAIL {
3964
3595
                pos = 0;
3965
3596
                lineno = 1;
3966
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3597
                job = parse_job (NULL, "test", buf, strlen (buf),
3967
3598
                                 &pos, &lineno);
3968
3599
 
3969
3600
                if (test_alloc_failed) {
3996
3627
        TEST_ALLOC_FAIL {
3997
3628
                pos = 0;
3998
3629
                lineno = 1;
3999
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3630
                job = parse_job (NULL, "test", buf, strlen (buf),
4000
3631
                                 &pos, &lineno);
4001
3632
 
4002
3633
                if (test_alloc_failed) {
4029
3660
 
4030
3661
        pos = 0;
4031
3662
        lineno = 1;
4032
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3663
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4033
3664
 
4034
3665
        TEST_EQ_P (job, NULL);
4035
3666
 
4048
3679
 
4049
3680
        pos = 0;
4050
3681
        lineno = 1;
4051
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3682
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4052
3683
 
4053
3684
        TEST_EQ_P (job, NULL);
4054
3685
 
4078
3709
        TEST_ALLOC_FAIL {
4079
3710
                pos = 0;
4080
3711
                lineno = 1;
4081
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3712
                job = parse_job (NULL, "test", buf, strlen (buf),
4082
3713
                                 &pos, &lineno);
4083
3714
 
4084
3715
                if (test_alloc_failed) {
4115
3746
        TEST_ALLOC_FAIL {
4116
3747
                pos = 0;
4117
3748
                lineno = 1;
4118
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3749
                job = parse_job (NULL, "test", buf, strlen (buf),
4119
3750
                                 &pos, &lineno);
4120
3751
 
4121
3752
                if (test_alloc_failed) {
4158
3789
        TEST_ALLOC_FAIL {
4159
3790
                pos = 0;
4160
3791
                lineno = 1;
4161
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3792
                job = parse_job (NULL, "test", buf, strlen (buf),
4162
3793
                                 &pos, &lineno);
4163
3794
 
4164
3795
                if (test_alloc_failed) {
4200
3831
 
4201
3832
        pos = 0;
4202
3833
        lineno = 1;
4203
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
3834
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4204
3835
 
4205
3836
        TEST_EQ_P (job, NULL);
4206
3837
 
4230
3861
        TEST_ALLOC_FAIL {
4231
3862
                pos = 0;
4232
3863
                lineno = 1;
4233
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3864
                job = parse_job (NULL, "test", buf, strlen (buf),
4234
3865
                                 &pos, &lineno);
4235
3866
 
4236
3867
                if (test_alloc_failed) {
4263
3894
        TEST_ALLOC_FAIL {
4264
3895
                pos = 0;
4265
3896
                lineno = 1;
4266
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3897
                job = parse_job (NULL, "test", buf, strlen (buf),
4267
3898
                                 &pos, &lineno);
4268
3899
 
4269
3900
                if (test_alloc_failed) {
4296
3927
        TEST_ALLOC_FAIL {
4297
3928
                pos = 0;
4298
3929
                lineno = 1;
4299
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3930
                job = parse_job (NULL, "test", buf, strlen (buf),
4300
3931
                                 &pos, &lineno);
4301
3932
 
4302
3933
                if (test_alloc_failed) {
4329
3960
        TEST_ALLOC_FAIL {
4330
3961
                pos = 0;
4331
3962
                lineno = 1;
4332
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3963
                job = parse_job (NULL, "test", buf, strlen (buf),
4333
3964
                                 &pos, &lineno);
4334
3965
 
4335
3966
                if (test_alloc_failed) {
4362
3993
        TEST_ALLOC_FAIL {
4363
3994
                pos = 0;
4364
3995
                lineno = 1;
4365
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
3996
                job = parse_job (NULL, "test", buf, strlen (buf),
4366
3997
                                 &pos, &lineno);
4367
3998
 
4368
3999
                if (test_alloc_failed) {
4394
4025
 
4395
4026
        pos = 0;
4396
4027
        lineno = 1;
4397
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4028
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4398
4029
 
4399
4030
        TEST_EQ_P (job, NULL);
4400
4031
 
4413
4044
 
4414
4045
        pos = 0;
4415
4046
        lineno = 1;
4416
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4047
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4417
4048
 
4418
4049
        TEST_EQ_P (job, NULL);
4419
4050
 
4432
4063
 
4433
4064
        pos = 0;
4434
4065
        lineno = 1;
4435
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4066
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4436
4067
 
4437
4068
        TEST_EQ_P (job, NULL);
4438
4069
 
4460
4091
        TEST_ALLOC_FAIL {
4461
4092
                pos = 0;
4462
4093
                lineno = 1;
4463
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4094
                job = parse_job (NULL, "test", buf, strlen (buf),
4464
4095
                                 &pos, &lineno);
4465
4096
 
4466
4097
                if (test_alloc_failed) {
4494
4125
        TEST_ALLOC_FAIL {
4495
4126
                pos = 0;
4496
4127
                lineno = 1;
4497
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4128
                job = parse_job (NULL, "test", buf, strlen (buf),
4498
4129
                                 &pos, &lineno);
4499
4130
 
4500
4131
                if (test_alloc_failed) {
4527
4158
        TEST_ALLOC_FAIL {
4528
4159
                pos = 0;
4529
4160
                lineno = 1;
4530
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4161
                job = parse_job (NULL, "test", buf, strlen (buf),
4531
4162
                                 &pos, &lineno);
4532
4163
 
4533
4164
                if (test_alloc_failed) {
4561
4192
        TEST_ALLOC_FAIL {
4562
4193
                pos = 0;
4563
4194
                lineno = 1;
4564
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4195
                job = parse_job (NULL, "test", buf, strlen (buf),
4565
4196
                                 &pos, &lineno);
4566
4197
 
4567
4198
                if (test_alloc_failed) {
4594
4225
        TEST_ALLOC_FAIL {
4595
4226
                pos = 0;
4596
4227
                lineno = 1;
4597
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4228
                job = parse_job (NULL, "test", buf, strlen (buf),
4598
4229
                                 &pos, &lineno);
4599
4230
 
4600
4231
                if (test_alloc_failed) {
4627
4258
 
4628
4259
        pos = 0;
4629
4260
        lineno = 1;
4630
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4261
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4631
4262
 
4632
4263
        TEST_EQ_P (job, NULL);
4633
4264
 
4646
4277
 
4647
4278
        pos = 0;
4648
4279
        lineno = 1;
4649
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4280
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4650
4281
 
4651
4282
        TEST_EQ_P (job, NULL);
4652
4283
 
4665
4296
 
4666
4297
        pos = 0;
4667
4298
        lineno = 1;
4668
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4299
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4669
4300
 
4670
4301
        TEST_EQ_P (job, NULL);
4671
4302
 
4684
4315
 
4685
4316
        pos = 0;
4686
4317
        lineno = 1;
4687
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4318
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4688
4319
 
4689
4320
        TEST_EQ_P (job, NULL);
4690
4321
 
4703
4334
 
4704
4335
        pos = 0;
4705
4336
        lineno = 1;
4706
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4337
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4707
4338
 
4708
4339
        TEST_EQ_P (job, NULL);
4709
4340
 
4722
4353
 
4723
4354
        pos = 0;
4724
4355
        lineno = 1;
4725
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4356
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4726
4357
 
4727
4358
        TEST_EQ_P (job, NULL);
4728
4359
 
4741
4372
 
4742
4373
        pos = 0;
4743
4374
        lineno = 1;
4744
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4375
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4745
4376
 
4746
4377
        TEST_EQ_P (job, NULL);
4747
4378
 
4760
4391
 
4761
4392
        pos = 0;
4762
4393
        lineno = 1;
4763
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4394
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4764
4395
 
4765
4396
        TEST_EQ_P (job, NULL);
4766
4397
 
4779
4410
 
4780
4411
        pos = 0;
4781
4412
        lineno = 1;
4782
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4413
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4783
4414
 
4784
4415
        TEST_EQ_P (job, NULL);
4785
4416
 
4798
4429
 
4799
4430
        pos = 0;
4800
4431
        lineno = 1;
4801
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4432
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4802
4433
 
4803
4434
        TEST_EQ_P (job, NULL);
4804
4435
 
4817
4448
 
4818
4449
        pos = 0;
4819
4450
        lineno = 1;
4820
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4451
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4821
4452
 
4822
4453
        TEST_EQ_P (job, NULL);
4823
4454
 
4836
4467
 
4837
4468
        pos = 0;
4838
4469
        lineno = 1;
4839
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4470
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4840
4471
 
4841
4472
        TEST_EQ_P (job, NULL);
4842
4473
 
4866
4497
        TEST_ALLOC_FAIL {
4867
4498
                pos = 0;
4868
4499
                lineno = 1;
4869
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4500
                job = parse_job (NULL, "test", buf, strlen (buf),
4870
4501
                                 &pos, &lineno);
4871
4502
 
4872
4503
                if (test_alloc_failed) {
4898
4529
        TEST_ALLOC_FAIL {
4899
4530
                pos = 0;
4900
4531
                lineno = 1;
4901
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4532
                job = parse_job (NULL, "test", buf, strlen (buf),
4902
4533
                                 &pos, &lineno);
4903
4534
 
4904
4535
                if (test_alloc_failed) {
4930
4561
 
4931
4562
        pos = 0;
4932
4563
        lineno = 1;
4933
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4564
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
4934
4565
 
4935
4566
        TEST_EQ_P (job, NULL);
4936
4567
 
4960
4591
        TEST_ALLOC_FAIL {
4961
4592
                pos = 0;
4962
4593
                lineno = 1;
4963
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4594
                job = parse_job (NULL, "test", buf, strlen (buf),
4964
4595
                                 &pos, &lineno);
4965
4596
 
4966
4597
                if (test_alloc_failed) {
4994
4625
        TEST_ALLOC_FAIL {
4995
4626
                pos = 0;
4996
4627
                lineno = 1;
4997
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4628
                job = parse_job (NULL, "test", buf, strlen (buf),
4998
4629
                                 &pos, &lineno);
4999
4630
 
5000
4631
                if (test_alloc_failed) {
5027
4658
 
5028
4659
        pos = 0;
5029
4660
        lineno = 1;
5030
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4661
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5031
4662
 
5032
4663
        TEST_EQ_P (job, NULL);
5033
4664
 
5046
4677
 
5047
4678
        pos = 0;
5048
4679
        lineno = 1;
5049
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4680
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5050
4681
 
5051
4682
        TEST_EQ_P (job, NULL);
5052
4683
 
5076
4707
        TEST_ALLOC_FAIL {
5077
4708
                pos = 0;
5078
4709
                lineno = 1;
5079
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4710
                job = parse_job (NULL, "test", buf, strlen (buf),
5080
4711
                                 &pos, &lineno);
5081
4712
 
5082
4713
                if (test_alloc_failed) {
5100
4731
        }
5101
4732
 
5102
4733
 
5103
 
        /* Check that a kill stanza with the signal argument and signal,
5104
 
         * sets the right signal on the jobs class.
5105
 
         */
5106
 
        TEST_FEATURE ("with signal and single argument");
5107
 
        strcpy (buf, "kill signal INT\n");
5108
 
 
5109
 
        TEST_ALLOC_FAIL {
5110
 
                pos = 0;
5111
 
                lineno = 1;
5112
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
5113
 
                                 &pos, &lineno);
5114
 
 
5115
 
                if (test_alloc_failed) {
5116
 
                        TEST_EQ_P (job, NULL);
5117
 
 
5118
 
                        err = nih_error_get ();
5119
 
                        TEST_EQ (err->number, ENOMEM);
5120
 
                        nih_free (err);
5121
 
 
5122
 
                        continue;
5123
 
                }
5124
 
 
5125
 
                TEST_EQ (pos, strlen (buf));
5126
 
                TEST_EQ (lineno, 2);
5127
 
 
5128
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
5129
 
 
5130
 
                TEST_EQ (job->kill_signal, SIGINT);
5131
 
 
5132
 
                nih_free (job);
5133
 
        }
5134
 
 
5135
 
        /* Check that a kill stanza with the signal argument and numeric signal,
5136
 
         * sets the right signal on the jobs class.
5137
 
         */
5138
 
        TEST_FEATURE ("with signal and single numeric argument");
5139
 
        strcpy (buf, "kill signal 30\n");
5140
 
 
5141
 
        TEST_ALLOC_FAIL {
5142
 
                pos = 0;
5143
 
                lineno = 1;
5144
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
5145
 
                                 &pos, &lineno);
5146
 
 
5147
 
                if (test_alloc_failed) {
5148
 
                        TEST_EQ_P (job, NULL);
5149
 
 
5150
 
                        err = nih_error_get ();
5151
 
                        TEST_EQ (err->number, ENOMEM);
5152
 
                        nih_free (err);
5153
 
 
5154
 
                        continue;
5155
 
                }
5156
 
 
5157
 
                TEST_EQ (pos, strlen (buf));
5158
 
                TEST_EQ (lineno, 2);
5159
 
 
5160
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
5161
 
 
5162
 
                /* Don't check symbolic here since different
5163
 
                 * architectures have different mappings.
5164
 
                 */
5165
 
                TEST_EQ (job->kill_signal, 30);
5166
 
 
5167
 
                nih_free (job);
5168
 
        }
5169
 
 
5170
4734
        /* Check that the last of multiple kill stanzas is used.
5171
4735
         */
5172
4736
        TEST_FEATURE ("with multiple timeout and single argument stanzas");
5176
4740
        TEST_ALLOC_FAIL {
5177
4741
                pos = 0;
5178
4742
                lineno = 1;
5179
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4743
                job = parse_job (NULL, "test", buf, strlen (buf),
5180
4744
                                 &pos, &lineno);
5181
4745
 
5182
4746
                if (test_alloc_failed) {
5200
4764
        }
5201
4765
 
5202
4766
 
5203
 
        TEST_FEATURE ("with multiple signal and single argument stanzas");
5204
 
        strcpy (buf, "kill signal INT\n");
5205
 
        strcat (buf, "kill signal TERM\n");
5206
 
 
5207
 
        TEST_ALLOC_FAIL {
5208
 
                pos = 0;
5209
 
                lineno = 1;
5210
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
5211
 
                                 &pos, &lineno);
5212
 
 
5213
 
                if (test_alloc_failed) {
5214
 
                        TEST_EQ_P (job, NULL);
5215
 
 
5216
 
                        err = nih_error_get ();
5217
 
                        TEST_EQ (err->number, ENOMEM);
5218
 
                        nih_free (err);
5219
 
 
5220
 
                        continue;
5221
 
                }
5222
 
 
5223
 
                TEST_EQ (pos, strlen (buf));
5224
 
                TEST_EQ (lineno, 3);
5225
 
 
5226
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
5227
 
 
5228
 
                TEST_EQ (job->kill_signal, SIGTERM);
5229
 
 
5230
 
                nih_free (job);
5231
 
        }
5232
 
 
5233
 
 
5234
4767
        /* Check that a kill stanza without an argument results in a syntax
5235
4768
         * error.
5236
4769
         */
5239
4772
 
5240
4773
        pos = 0;
5241
4774
        lineno = 1;
5242
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4775
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5243
4776
 
5244
4777
        TEST_EQ_P (job, NULL);
5245
4778
 
5258
4791
 
5259
4792
        pos = 0;
5260
4793
        lineno = 1;
5261
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4794
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5262
4795
 
5263
4796
        TEST_EQ_P (job, NULL);
5264
4797
 
5277
4810
 
5278
4811
        pos = 0;
5279
4812
        lineno = 1;
5280
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4813
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5281
4814
 
5282
4815
        TEST_EQ_P (job, NULL);
5283
4816
 
5288
4821
        nih_free (err);
5289
4822
 
5290
4823
 
5291
 
        /* Check that a kill stanza with the timeout argument but no timeout
5292
 
         * results in a syntax error.
5293
 
         */
5294
 
        TEST_FEATURE ("with signal and missing argument");
5295
 
        strcpy (buf, "kill signal\n");
5296
 
 
5297
 
        pos = 0;
5298
 
        lineno = 1;
5299
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
5300
 
 
5301
 
        TEST_EQ_P (job, NULL);
5302
 
 
5303
 
        err = nih_error_get ();
5304
 
        TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
5305
 
        TEST_EQ (pos, 11);
5306
 
        TEST_EQ (lineno, 1);
5307
 
        nih_free (err);
5308
 
 
5309
 
 
5310
4824
        /* Check that a kill timeout stanza with a non-integer argument
5311
4825
         * results in a syntax error.
5312
4826
         */
5315
4829
 
5316
4830
        pos = 0;
5317
4831
        lineno = 1;
5318
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4832
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5319
4833
 
5320
4834
        TEST_EQ_P (job, NULL);
5321
4835
 
5334
4848
 
5335
4849
        pos = 0;
5336
4850
        lineno = 1;
5337
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4851
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5338
4852
 
5339
4853
        TEST_EQ_P (job, NULL);
5340
4854
 
5353
4867
 
5354
4868
        pos = 0;
5355
4869
        lineno = 1;
5356
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4870
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5357
4871
 
5358
4872
        TEST_EQ_P (job, NULL);
5359
4873
 
5372
4886
 
5373
4887
        pos = 0;
5374
4888
        lineno = 1;
5375
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4889
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5376
4890
 
5377
4891
        TEST_EQ_P (job, NULL);
5378
4892
 
5383
4897
        nih_free (err);
5384
4898
 
5385
4899
 
5386
 
        /* Check that a kill signal stanza with an unknown signal argument
5387
 
         * results in a syntax error.
5388
 
         */
5389
 
        TEST_FEATURE ("with signal and unknown signal argument");
5390
 
        strcpy (buf, "kill signal foo\n");
5391
 
 
5392
 
        pos = 0;
5393
 
        lineno = 1;
5394
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
5395
 
 
5396
 
        TEST_EQ_P (job, NULL);
5397
 
 
5398
 
        err = nih_error_get ();
5399
 
        TEST_EQ (err->number, PARSE_ILLEGAL_SIGNAL);
5400
 
        TEST_EQ (pos, 12);
5401
 
        TEST_EQ (lineno, 1);
5402
 
        nih_free (err);
5403
 
 
5404
 
 
5405
4900
        /* Check that a kill stanza with the timeout argument and timeout,
5406
4901
         * but with an extra argument afterwards results in a syntax
5407
4902
         * error.
5411
4906
 
5412
4907
        pos = 0;
5413
4908
        lineno = 1;
5414
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
5415
 
 
5416
 
        TEST_EQ_P (job, NULL);
5417
 
 
5418
 
        err = nih_error_get ();
5419
 
        TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
5420
 
        TEST_EQ (pos, 16);
5421
 
        TEST_EQ (lineno, 1);
5422
 
        nih_free (err);
5423
 
 
5424
 
 
5425
 
        /* Check that a kill stanza with the signal argument and signal,
5426
 
         * but with an extra argument afterwards results in a syntax
5427
 
         * error.
5428
 
         */
5429
 
        TEST_FEATURE ("with signal and extra argument");
5430
 
        strcpy (buf, "kill signal INT foo\n");
5431
 
 
5432
 
        pos = 0;
5433
 
        lineno = 1;
5434
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
4909
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5435
4910
 
5436
4911
        TEST_EQ_P (job, NULL);
5437
4912
 
5462
4937
        TEST_ALLOC_FAIL {
5463
4938
                pos = 0;
5464
4939
                lineno = 1;
5465
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4940
                job = parse_job (NULL, "test", buf, strlen (buf),
5466
4941
                                 &pos, &lineno);
5467
4942
 
5468
4943
                if (test_alloc_failed) {
5501
4976
        TEST_ALLOC_FAIL {
5502
4977
                pos = 0;
5503
4978
                lineno = 1;
5504
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
4979
                job = parse_job (NULL, "test", buf, strlen (buf),
5505
4980
                                 &pos, &lineno);
5506
4981
 
5507
4982
                if (test_alloc_failed) {
5540
5015
        TEST_ALLOC_FAIL {
5541
5016
                pos = 0;
5542
5017
                lineno = 1;
5543
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5018
                job = parse_job (NULL, "test", buf, strlen (buf),
5544
5019
                                 &pos, &lineno);
5545
5020
 
5546
5021
                if (test_alloc_failed) {
5584
5059
        TEST_ALLOC_FAIL {
5585
5060
                pos = 0;
5586
5061
                lineno = 1;
5587
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5062
                job = parse_job (NULL, "test", buf, strlen (buf),
5588
5063
                                 &pos, &lineno);
5589
5064
 
5590
5065
                if (test_alloc_failed) {
5625
5100
 
5626
5101
        pos = 0;
5627
5102
        lineno = 1;
5628
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5103
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5629
5104
 
5630
5105
        TEST_EQ_P (job, NULL);
5631
5106
 
5644
5119
 
5645
5120
        pos = 0;
5646
5121
        lineno = 1;
5647
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5122
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5648
5123
 
5649
5124
        TEST_EQ_P (job, NULL);
5650
5125
 
5663
5138
 
5664
5139
        pos = 0;
5665
5140
        lineno = 1;
5666
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5141
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5667
5142
 
5668
5143
        TEST_EQ_P (job, NULL);
5669
5144
 
5682
5157
 
5683
5158
        pos = 0;
5684
5159
        lineno = 1;
5685
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5160
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5686
5161
 
5687
5162
        TEST_EQ_P (job, NULL);
5688
5163
 
5701
5176
 
5702
5177
        pos = 0;
5703
5178
        lineno = 1;
5704
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5179
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5705
5180
 
5706
5181
        TEST_EQ_P (job, NULL);
5707
5182
 
5720
5195
 
5721
5196
        pos = 0;
5722
5197
        lineno = 1;
5723
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5198
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5724
5199
 
5725
5200
        TEST_EQ_P (job, NULL);
5726
5201
 
5732
5207
}
5733
5208
 
5734
5209
void
 
5210
test_stanza_session (void)
 
5211
{
 
5212
        JobClass*job;
 
5213
        NihError *err;
 
5214
        size_t    pos, lineno;
 
5215
        char      buf[1024];
 
5216
 
 
5217
        TEST_FUNCTION ("stanza_session");
 
5218
 
 
5219
        /* Check that session leader sets the job's to be a session leader.
 
5220
         */
 
5221
        TEST_FEATURE ("with leader argument");
 
5222
        strcpy (buf, "session leader\n");
 
5223
 
 
5224
        TEST_ALLOC_FAIL {
 
5225
                pos = 0;
 
5226
                lineno = 1;
 
5227
                job = parse_job (NULL, "test", buf, strlen (buf),
 
5228
                                 &pos, &lineno);
 
5229
 
 
5230
                if (test_alloc_failed) {
 
5231
                        TEST_EQ_P (job, NULL);
 
5232
 
 
5233
                        err = nih_error_get ();
 
5234
                        TEST_EQ (err->number, ENOMEM);
 
5235
                        nih_free (err);
 
5236
 
 
5237
                        continue;
 
5238
                }
 
5239
 
 
5240
                TEST_EQ (pos, strlen (buf));
 
5241
                TEST_EQ (lineno, 2);
 
5242
 
 
5243
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
 
5244
 
 
5245
                TEST_EQ (job->console, CONSOLE_NONE);
 
5246
 
 
5247
                nih_free (job);
 
5248
        }
 
5249
 
 
5250
 
 
5251
        /* Check that multiple stanzas are ok.
 
5252
         */
 
5253
        TEST_FEATURE ("with multiple stanzas");
 
5254
        strcpy (buf, "session leader\n");
 
5255
        strcat (buf, "session leader\n");
 
5256
 
 
5257
        TEST_ALLOC_FAIL {
 
5258
                pos = 0;
 
5259
                lineno = 1;
 
5260
                job = parse_job (NULL, "test", buf, strlen (buf),
 
5261
                                 &pos, &lineno);
 
5262
 
 
5263
                if (test_alloc_failed) {
 
5264
                        TEST_EQ_P (job, NULL);
 
5265
 
 
5266
                        err = nih_error_get ();
 
5267
                        TEST_EQ (err->number, ENOMEM);
 
5268
                        nih_free (err);
 
5269
 
 
5270
                        continue;
 
5271
                }
 
5272
 
 
5273
                TEST_EQ (pos, strlen (buf));
 
5274
                TEST_EQ (lineno, 3);
 
5275
 
 
5276
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
 
5277
 
 
5278
                TEST_EQ (job->leader, TRUE);
 
5279
 
 
5280
                nih_free (job);
 
5281
        }
 
5282
 
 
5283
 
 
5284
        /* Check that an unknown argument raises a syntax error.
 
5285
         */
 
5286
        TEST_FEATURE ("with unknown argument");
 
5287
        strcpy (buf, "session wibble\n");
 
5288
 
 
5289
        pos = 0;
 
5290
        lineno = 1;
 
5291
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5292
 
 
5293
        TEST_EQ_P (job, NULL);
 
5294
 
 
5295
        err = nih_error_get ();
 
5296
        TEST_EQ (err->number, NIH_CONFIG_UNKNOWN_STANZA);
 
5297
        TEST_EQ (pos, 8);
 
5298
        TEST_EQ (lineno, 1);
 
5299
        nih_free (err);
 
5300
 
 
5301
 
 
5302
        /* Check that additional arguments to the stanza results in
 
5303
         * a syntax error.
 
5304
         */
 
5305
        TEST_FEATURE ("with argument");
 
5306
        strcpy (buf, "session leader foo\n");
 
5307
 
 
5308
        pos = 0;
 
5309
        lineno = 1;
 
5310
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5311
 
 
5312
        TEST_EQ_P (job, NULL);
 
5313
 
 
5314
        err = nih_error_get ();
 
5315
        TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
 
5316
        TEST_EQ (pos, 15);
 
5317
        TEST_EQ (lineno, 1);
 
5318
        nih_free (err);
 
5319
 
 
5320
 
 
5321
        /* Check that a missing argument raises a syntax error.
 
5322
         */
 
5323
        TEST_FEATURE ("with missing argument");
 
5324
        strcpy (buf, "session\n");
 
5325
 
 
5326
        pos = 0;
 
5327
        lineno = 1;
 
5328
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5329
 
 
5330
        TEST_EQ_P (job, NULL);
 
5331
 
 
5332
        err = nih_error_get ();
 
5333
        TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
 
5334
        TEST_EQ (pos, 7);
 
5335
        TEST_EQ (lineno, 1);
 
5336
        nih_free (err);
 
5337
}
 
5338
 
 
5339
void
5735
5340
test_stanza_console (void)
5736
5341
{
5737
5342
        JobClass*job;
5750
5355
        TEST_ALLOC_FAIL {
5751
5356
                pos = 0;
5752
5357
                lineno = 1;
5753
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5358
                job = parse_job (NULL, "test", buf, strlen (buf),
5754
5359
                                 &pos, &lineno);
5755
5360
 
5756
5361
                if (test_alloc_failed) {
5783
5388
        TEST_ALLOC_FAIL {
5784
5389
                pos = 0;
5785
5390
                lineno = 1;
5786
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5391
                job = parse_job (NULL, "test", buf, strlen (buf),
5787
5392
                                 &pos, &lineno);
5788
5393
 
5789
5394
                if (test_alloc_failed) {
5816
5421
        TEST_ALLOC_FAIL {
5817
5422
                pos = 0;
5818
5423
                lineno = 1;
5819
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5424
                job = parse_job (NULL, "test", buf, strlen (buf),
5820
5425
                                 &pos, &lineno);
5821
5426
 
5822
5427
                if (test_alloc_failed) {
5840
5445
        }
5841
5446
 
5842
5447
 
5843
 
        /* Check that console log sets the job's console to
5844
 
         * CONSOLE_LOG.
5845
 
         */
5846
 
        TEST_FEATURE ("with log argument");
5847
 
        strcpy (buf, "console log\n");
5848
 
 
5849
 
        TEST_ALLOC_FAIL {
5850
 
                pos = 0;
5851
 
                lineno = 1;
5852
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
5853
 
                                 &pos, &lineno);
5854
 
 
5855
 
                if (test_alloc_failed) {
5856
 
                        TEST_EQ_P (job, NULL);
5857
 
 
5858
 
                        err = nih_error_get ();
5859
 
                        TEST_EQ (err->number, ENOMEM);
5860
 
                        nih_free (err);
5861
 
 
5862
 
                        continue;
5863
 
                }
5864
 
 
5865
 
                TEST_EQ (pos, strlen (buf));
5866
 
                TEST_EQ (lineno, 2);
5867
 
 
5868
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
5869
 
 
5870
 
                TEST_EQ (job->console, CONSOLE_LOG);
5871
 
 
5872
 
                nih_free (job);
5873
 
        }
5874
 
 
5875
5448
        /* Check that the last of multiple console stanzas is used.
5876
5449
         */
5877
5450
        TEST_FEATURE ("with multiple stanzas");
5881
5454
        TEST_ALLOC_FAIL {
5882
5455
                pos = 0;
5883
5456
                lineno = 1;
5884
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5457
                job = parse_job (NULL, "test", buf, strlen (buf),
5885
5458
                                 &pos, &lineno);
5886
5459
 
5887
5460
                if (test_alloc_failed) {
5912
5485
 
5913
5486
        pos = 0;
5914
5487
        lineno = 1;
5915
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5488
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5916
5489
 
5917
5490
        TEST_EQ_P (job, NULL);
5918
5491
 
5931
5504
 
5932
5505
        pos = 0;
5933
5506
        lineno = 1;
5934
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5507
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5935
5508
 
5936
5509
        TEST_EQ_P (job, NULL);
5937
5510
 
5949
5522
 
5950
5523
        pos = 0;
5951
5524
        lineno = 1;
5952
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5525
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
5953
5526
 
5954
5527
        TEST_EQ_P (job, NULL);
5955
5528
 
5979
5552
        TEST_ALLOC_FAIL {
5980
5553
                pos = 0;
5981
5554
                lineno = 1;
5982
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5555
                job = parse_job (NULL, "test", buf, strlen (buf),
5983
5556
                                 &pos, &lineno);
5984
5557
 
5985
5558
                if (test_alloc_failed) {
6017
5590
        TEST_ALLOC_FAIL {
6018
5591
                pos = 0;
6019
5592
                lineno = 1;
6020
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5593
                job = parse_job (NULL, "test", buf, strlen (buf),
6021
5594
                                 &pos, &lineno);
6022
5595
 
6023
5596
                if (test_alloc_failed) {
6054
5627
 
6055
5628
        pos = 0;
6056
5629
        lineno = 1;
6057
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5630
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6058
5631
 
6059
5632
        TEST_EQ_P (job, NULL);
6060
5633
 
6073
5646
 
6074
5647
        pos = 0;
6075
5648
        lineno = 1;
6076
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5649
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6077
5650
 
6078
5651
        TEST_EQ_P (job, NULL);
6079
5652
 
6103
5676
        TEST_ALLOC_FAIL {
6104
5677
                pos = 0;
6105
5678
                lineno = 1;
6106
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5679
                job = parse_job (NULL, "test", buf, strlen (buf),
6107
5680
                                 &pos, &lineno);
6108
5681
 
6109
5682
                if (test_alloc_failed) {
6140
5713
        TEST_ALLOC_FAIL {
6141
5714
                pos = 0;
6142
5715
                lineno = 1;
6143
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5716
                job = parse_job (NULL, "test", buf, strlen (buf),
6144
5717
                                 &pos, &lineno);
6145
5718
 
6146
5719
                if (test_alloc_failed) {
6183
5756
        TEST_ALLOC_FAIL {
6184
5757
                pos = 0;
6185
5758
                lineno = 1;
6186
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5759
                job = parse_job (NULL, "test", buf, strlen (buf),
6187
5760
                                 &pos, &lineno);
6188
5761
 
6189
5762
                if (test_alloc_failed) {
6225
5798
 
6226
5799
        pos = 0;
6227
5800
        lineno = 1;
6228
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5801
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6229
5802
 
6230
5803
        TEST_EQ_P (job, NULL);
6231
5804
 
6255
5828
        TEST_ALLOC_FAIL {
6256
5829
                pos = 0;
6257
5830
                lineno = 1;
6258
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5831
                job = parse_job (NULL, "test", buf, strlen (buf),
6259
5832
                                 &pos, &lineno);
6260
5833
 
6261
5834
                if (test_alloc_failed) {
6288
5861
        TEST_ALLOC_FAIL {
6289
5862
                pos = 0;
6290
5863
                lineno = 1;
6291
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
5864
                job = parse_job (NULL, "test", buf, strlen (buf),
6292
5865
                                 &pos, &lineno);
6293
5866
 
6294
5867
                if (test_alloc_failed) {
6320
5893
 
6321
5894
        pos = 0;
6322
5895
        lineno = 1;
6323
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5896
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6324
5897
 
6325
5898
        TEST_EQ_P (job, NULL);
6326
5899
 
6339
5912
 
6340
5913
        pos = 0;
6341
5914
        lineno = 1;
6342
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5915
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6343
5916
 
6344
5917
        TEST_EQ_P (job, NULL);
6345
5918
 
6358
5931
 
6359
5932
        pos = 0;
6360
5933
        lineno = 1;
6361
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5934
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6362
5935
 
6363
5936
        TEST_EQ_P (job, NULL);
6364
5937
 
6377
5950
 
6378
5951
        pos = 0;
6379
5952
        lineno = 1;
6380
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5953
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6381
5954
 
6382
5955
        TEST_EQ_P (job, NULL);
6383
5956
 
6396
5969
 
6397
5970
        pos = 0;
6398
5971
        lineno = 1;
6399
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5972
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6400
5973
 
6401
5974
        TEST_EQ_P (job, NULL);
6402
5975
 
6416
5989
 
6417
5990
        pos = 0;
6418
5991
        lineno = 1;
6419
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
5992
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6420
5993
 
6421
5994
        TEST_EQ_P (job, NULL);
6422
5995
 
6446
6019
        TEST_ALLOC_FAIL {
6447
6020
                pos = 0;
6448
6021
                lineno = 1;
6449
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6022
                job = parse_job (NULL, "test", buf, strlen (buf),
6450
6023
                                 &pos, &lineno);
6451
6024
 
6452
6025
                if (test_alloc_failed) {
6479
6052
        TEST_ALLOC_FAIL {
6480
6053
                pos = 0;
6481
6054
                lineno = 1;
6482
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6055
                job = parse_job (NULL, "test", buf, strlen (buf),
6483
6056
                                 &pos, &lineno);
6484
6057
 
6485
6058
                if (test_alloc_failed) {
6512
6085
        TEST_ALLOC_FAIL {
6513
6086
                pos = 0;
6514
6087
                lineno = 1;
6515
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6088
                job = parse_job (NULL, "test", buf, strlen (buf),
6516
6089
                                 &pos, &lineno);
6517
6090
 
6518
6091
                if (test_alloc_failed) {
6544
6117
 
6545
6118
        pos = 0;
6546
6119
        lineno = 1;
6547
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
6120
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6548
6121
 
6549
6122
        TEST_EQ_P (job, NULL);
6550
6123
 
6563
6136
 
6564
6137
        pos = 0;
6565
6138
        lineno = 1;
6566
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
6139
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6567
6140
 
6568
6141
        TEST_EQ_P (job, NULL);
6569
6142
 
6582
6155
 
6583
6156
        pos = 0;
6584
6157
        lineno = 1;
6585
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
6158
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6586
6159
 
6587
6160
        TEST_EQ_P (job, NULL);
6588
6161
 
6601
6174
 
6602
6175
        pos = 0;
6603
6176
        lineno = 1;
6604
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
6177
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6605
6178
 
6606
6179
        TEST_EQ_P (job, NULL);
6607
6180
 
6620
6193
 
6621
6194
        pos = 0;
6622
6195
        lineno = 1;
6623
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
6196
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6624
6197
 
6625
6198
        TEST_EQ_P (job, NULL);
6626
6199
 
6639
6212
 
6640
6213
        pos = 0;
6641
6214
        lineno = 1;
6642
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
6215
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6643
6216
 
6644
6217
        TEST_EQ_P (job, NULL);
6645
6218
 
6650
6223
        nih_free (err);
6651
6224
}
6652
6225
 
6653
 
#define ADJ_TO_SCORE(x) ((x * 1000) / ((x < 0) ? 17 : 15))
6654
 
 
6655
6226
void
6656
6227
test_stanza_oom (void)
6657
6228
{
6671
6242
        TEST_ALLOC_FAIL {
6672
6243
                pos = 0;
6673
6244
                lineno = 1;
6674
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6675
 
                                 &pos, &lineno);
6676
 
 
6677
 
                if (test_alloc_failed) {
6678
 
                        TEST_EQ_P (job, NULL);
6679
 
 
6680
 
                        err = nih_error_get ();
6681
 
                        TEST_EQ (err->number, ENOMEM);
6682
 
                        nih_free (err);
6683
 
 
6684
 
                        continue;
6685
 
                }
6686
 
 
6687
 
                TEST_EQ (pos, strlen (buf));
6688
 
                TEST_EQ (lineno, 2);
6689
 
 
6690
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
6691
 
 
6692
 
                TEST_EQ (job->oom_score_adj, ADJ_TO_SCORE(10));
6693
 
 
6694
 
                nih_free (job);
6695
 
        }
6696
 
 
6697
 
        TEST_FEATURE ("with positive score argument");
6698
 
        strcpy (buf, "oom score 100\n");
6699
 
 
6700
 
        TEST_ALLOC_FAIL {
6701
 
                pos = 0;
6702
 
                lineno = 1;
6703
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6704
 
                                 &pos, &lineno);
6705
 
 
6706
 
                if (test_alloc_failed) {
6707
 
                        TEST_EQ_P (job, NULL);
6708
 
 
6709
 
                        err = nih_error_get ();
6710
 
                        TEST_EQ (err->number, ENOMEM);
6711
 
                        nih_free (err);
6712
 
 
6713
 
                        continue;
6714
 
                }
6715
 
 
6716
 
                TEST_EQ (pos, strlen (buf));
6717
 
                TEST_EQ (lineno, 2);
6718
 
 
6719
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
6720
 
 
6721
 
                TEST_EQ (job->oom_score_adj, 100);
6722
 
 
6723
 
                nih_free (job);
6724
 
        }
 
6245
                job = parse_job (NULL, "test", buf, strlen (buf),
 
6246
                                 &pos, &lineno);
 
6247
 
 
6248
                if (test_alloc_failed) {
 
6249
                        TEST_EQ_P (job, NULL);
 
6250
 
 
6251
                        err = nih_error_get ();
 
6252
                        TEST_EQ (err->number, ENOMEM);
 
6253
                        nih_free (err);
 
6254
 
 
6255
                        continue;
 
6256
                }
 
6257
 
 
6258
                TEST_EQ (pos, strlen (buf));
 
6259
                TEST_EQ (lineno, 2);
 
6260
 
 
6261
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
 
6262
 
 
6263
                TEST_EQ (job->oom_adj, 10);
 
6264
 
 
6265
                nih_free (job);
 
6266
        }
 
6267
 
6725
6268
 
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 {
6733
6276
                pos = 0;
6734
6277
                lineno = 1;
6735
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6736
 
                                 &pos, &lineno);
6737
 
 
6738
 
                if (test_alloc_failed) {
6739
 
                        TEST_EQ_P (job, NULL);
6740
 
 
6741
 
                        err = nih_error_get ();
6742
 
                        TEST_EQ (err->number, ENOMEM);
6743
 
                        nih_free (err);
6744
 
 
6745
 
                        continue;
6746
 
                }
6747
 
 
6748
 
                TEST_EQ (pos, strlen (buf));
6749
 
                TEST_EQ (lineno, 2);
6750
 
 
6751
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
6752
 
 
6753
 
                TEST_EQ (job->oom_score_adj, ADJ_TO_SCORE(-10));
6754
 
 
6755
 
                nih_free (job);
6756
 
        }
6757
 
 
6758
 
        TEST_FEATURE ("with negative score argument");
6759
 
        strcpy (buf, "oom score -100\n");
6760
 
 
6761
 
        TEST_ALLOC_FAIL {
6762
 
                pos = 0;
6763
 
                lineno = 1;
6764
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6765
 
                                 &pos, &lineno);
6766
 
 
6767
 
                if (test_alloc_failed) {
6768
 
                        TEST_EQ_P (job, NULL);
6769
 
 
6770
 
                        err = nih_error_get ();
6771
 
                        TEST_EQ (err->number, ENOMEM);
6772
 
                        nih_free (err);
6773
 
 
6774
 
                        continue;
6775
 
                }
6776
 
 
6777
 
                TEST_EQ (pos, strlen (buf));
6778
 
                TEST_EQ (lineno, 2);
6779
 
 
6780
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
6781
 
 
6782
 
                TEST_EQ (job->oom_score_adj, -100);
 
6278
                job = parse_job (NULL, "test", buf, strlen (buf),
 
6279
                                 &pos, &lineno);
 
6280
 
 
6281
                if (test_alloc_failed) {
 
6282
                        TEST_EQ_P (job, NULL);
 
6283
 
 
6284
                        err = nih_error_get ();
 
6285
                        TEST_EQ (err->number, ENOMEM);
 
6286
                        nih_free (err);
 
6287
 
 
6288
                        continue;
 
6289
                }
 
6290
 
 
6291
                TEST_EQ (pos, strlen (buf));
 
6292
                TEST_EQ (lineno, 2);
 
6293
 
 
6294
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
 
6295
 
 
6296
                TEST_EQ (job->oom_adj, -10);
6783
6297
 
6784
6298
                nih_free (job);
6785
6299
        }
6794
6308
        TEST_ALLOC_FAIL {
6795
6309
                pos = 0;
6796
6310
                lineno = 1;
6797
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6798
 
                                 &pos, &lineno);
6799
 
 
6800
 
                if (test_alloc_failed) {
6801
 
                        TEST_EQ_P (job, NULL);
6802
 
 
6803
 
                        err = nih_error_get ();
6804
 
                        TEST_EQ (err->number, ENOMEM);
6805
 
                        nih_free (err);
6806
 
 
6807
 
                        continue;
6808
 
                }
6809
 
 
6810
 
                TEST_EQ (pos, strlen (buf));
6811
 
                TEST_EQ (lineno, 2);
6812
 
 
6813
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
6814
 
 
6815
 
                TEST_EQ (job->oom_score_adj, ADJ_TO_SCORE(-17));
6816
 
 
6817
 
                nih_free (job);
6818
 
        }
6819
 
 
6820
 
 
6821
 
        /* Check that an oom score stanza may have the special never
6822
 
         *  argument which stores -1000 in the job.
6823
 
         */
6824
 
        TEST_FEATURE ("with never score argument");
6825
 
        strcpy (buf, "oom score never\n");
6826
 
 
6827
 
        TEST_ALLOC_FAIL {
6828
 
                pos = 0;
6829
 
                lineno = 1;
6830
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6831
 
                                 &pos, &lineno);
6832
 
 
6833
 
                if (test_alloc_failed) {
6834
 
                        TEST_EQ_P (job, NULL);
6835
 
 
6836
 
                        err = nih_error_get ();
6837
 
                        TEST_EQ (err->number, ENOMEM);
6838
 
                        nih_free (err);
6839
 
 
6840
 
                        continue;
6841
 
                }
6842
 
 
6843
 
                TEST_EQ (pos, strlen (buf));
6844
 
                TEST_EQ (lineno, 2);
6845
 
 
6846
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
6847
 
 
6848
 
                TEST_EQ (job->oom_score_adj, -1000);
 
6311
                job = parse_job (NULL, "test", buf, strlen (buf),
 
6312
                                 &pos, &lineno);
 
6313
 
 
6314
                if (test_alloc_failed) {
 
6315
                        TEST_EQ_P (job, NULL);
 
6316
 
 
6317
                        err = nih_error_get ();
 
6318
                        TEST_EQ (err->number, ENOMEM);
 
6319
                        nih_free (err);
 
6320
 
 
6321
                        continue;
 
6322
                }
 
6323
 
 
6324
                TEST_EQ (pos, strlen (buf));
 
6325
                TEST_EQ (lineno, 2);
 
6326
 
 
6327
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
 
6328
 
 
6329
                TEST_EQ (job->oom_adj, -17);
6849
6330
 
6850
6331
                nih_free (job);
6851
6332
        }
6860
6341
        TEST_ALLOC_FAIL {
6861
6342
                pos = 0;
6862
6343
                lineno = 1;
6863
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6864
 
                                 &pos, &lineno);
6865
 
 
6866
 
                if (test_alloc_failed) {
6867
 
                        TEST_EQ_P (job, NULL);
6868
 
 
6869
 
                        err = nih_error_get ();
6870
 
                        TEST_EQ (err->number, ENOMEM);
6871
 
                        nih_free (err);
6872
 
 
6873
 
                        continue;
6874
 
                }
6875
 
 
6876
 
                TEST_EQ (pos, strlen (buf));
6877
 
                TEST_EQ (lineno, 3);
6878
 
 
6879
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
6880
 
 
6881
 
                TEST_EQ (job->oom_score_adj, ADJ_TO_SCORE(10));
6882
 
 
6883
 
                nih_free (job);
6884
 
        }
6885
 
 
6886
 
        TEST_FEATURE ("with multiple score stanzas");
6887
 
        strcpy (buf, "oom score -500\n");
6888
 
        strcat (buf, "oom score 500\n");
6889
 
 
6890
 
        TEST_ALLOC_FAIL {
6891
 
                pos = 0;
6892
 
                lineno = 1;
6893
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6894
 
                                 &pos, &lineno);
6895
 
 
6896
 
                if (test_alloc_failed) {
6897
 
                        TEST_EQ_P (job, NULL);
6898
 
 
6899
 
                        err = nih_error_get ();
6900
 
                        TEST_EQ (err->number, ENOMEM);
6901
 
                        nih_free (err);
6902
 
 
6903
 
                        continue;
6904
 
                }
6905
 
 
6906
 
                TEST_EQ (pos, strlen (buf));
6907
 
                TEST_EQ (lineno, 3);
6908
 
 
6909
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
6910
 
 
6911
 
                TEST_EQ (job->oom_score_adj, 500);
6912
 
 
6913
 
                nih_free (job);
6914
 
        }
6915
 
 
6916
 
        /* Check that the last of multiple distinct oom stanzas is
6917
 
         * used.
6918
 
         */
6919
 
        TEST_FEATURE ("with an oom overriding an oom score stanza");
6920
 
        strcpy (buf, "oom score -10\n");
6921
 
        strcat (buf, "oom 10\n");
6922
 
 
6923
 
        TEST_ALLOC_FAIL {
6924
 
                pos = 0;
6925
 
                lineno = 1;
6926
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6927
 
                                 &pos, &lineno);
6928
 
 
6929
 
                if (test_alloc_failed) {
6930
 
                        TEST_EQ_P (job, NULL);
6931
 
 
6932
 
                        err = nih_error_get ();
6933
 
                        TEST_EQ (err->number, ENOMEM);
6934
 
                        nih_free (err);
6935
 
 
6936
 
                        continue;
6937
 
                }
6938
 
 
6939
 
                TEST_EQ (pos, strlen (buf));
6940
 
                TEST_EQ (lineno, 3);
6941
 
 
6942
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
6943
 
 
6944
 
                TEST_EQ (job->oom_score_adj, ADJ_TO_SCORE(10));
6945
 
 
6946
 
                nih_free (job);
6947
 
        }
6948
 
 
6949
 
        TEST_FEATURE ("with an oom score overriding an oom stanza");
6950
 
        strcpy (buf, "oom -10\n");
6951
 
        strcat (buf, "oom score 10\n");
6952
 
 
6953
 
        TEST_ALLOC_FAIL {
6954
 
                pos = 0;
6955
 
                lineno = 1;
6956
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
6957
 
                                 &pos, &lineno);
6958
 
 
6959
 
                if (test_alloc_failed) {
6960
 
                        TEST_EQ_P (job, NULL);
6961
 
 
6962
 
                        err = nih_error_get ();
6963
 
                        TEST_EQ (err->number, ENOMEM);
6964
 
                        nih_free (err);
6965
 
 
6966
 
                        continue;
6967
 
                }
6968
 
 
6969
 
                TEST_EQ (pos, strlen (buf));
6970
 
                TEST_EQ (lineno, 3);
6971
 
 
6972
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
6973
 
 
6974
 
                TEST_EQ (job->oom_score_adj, 10);
 
6344
                job = parse_job (NULL, "test", buf, strlen (buf),
 
6345
                                 &pos, &lineno);
 
6346
 
 
6347
                if (test_alloc_failed) {
 
6348
                        TEST_EQ_P (job, NULL);
 
6349
 
 
6350
                        err = nih_error_get ();
 
6351
                        TEST_EQ (err->number, ENOMEM);
 
6352
                        nih_free (err);
 
6353
 
 
6354
                        continue;
 
6355
                }
 
6356
 
 
6357
                TEST_EQ (pos, strlen (buf));
 
6358
                TEST_EQ (lineno, 3);
 
6359
 
 
6360
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
 
6361
 
 
6362
                TEST_EQ (job->oom_adj, 10);
6975
6363
 
6976
6364
                nih_free (job);
6977
6365
        }
6985
6373
 
6986
6374
        pos = 0;
6987
6375
        lineno = 1;
6988
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
6376
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
6989
6377
 
6990
6378
        TEST_EQ_P (job, NULL);
6991
6379
 
6996
6384
        nih_free (err);
6997
6385
 
6998
6386
 
6999
 
        /* Check that an oom score stanza without an argument results in a
7000
 
         * syntax error.
7001
 
         */
7002
 
        TEST_FEATURE ("with missing score argument");
7003
 
        strcpy (buf, "oom score\n");
7004
 
 
7005
 
        pos = 0;
7006
 
        lineno = 1;
7007
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
7008
 
 
7009
 
        TEST_EQ_P (job, NULL);
7010
 
 
7011
 
        err = nih_error_get ();
7012
 
        TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
7013
 
        TEST_EQ (pos, 9);
7014
 
        TEST_EQ (lineno, 1);
7015
 
        nih_free (err);
7016
 
 
7017
 
 
7018
6387
        /* Check that an oom stanza with an overly large argument results
7019
6388
         * in a syntax error.
7020
6389
         */
7023
6392
 
7024
6393
        pos = 0;
7025
6394
        lineno = 1;
7026
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
6395
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7027
6396
 
7028
6397
        TEST_EQ_P (job, NULL);
7029
6398
 
7033
6402
        TEST_EQ (lineno, 1);
7034
6403
        nih_free (err);
7035
6404
 
7036
 
        TEST_FEATURE ("with overly large score argument");
7037
 
        strcpy (buf, "oom score 1200\n");
7038
 
 
7039
 
        pos = 0;
7040
 
        lineno = 1;
7041
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
7042
 
 
7043
 
        TEST_EQ_P (job, NULL);
7044
 
 
7045
 
        err = nih_error_get ();
7046
 
        TEST_EQ (err->number, PARSE_ILLEGAL_OOM);
7047
 
        TEST_EQ (pos, 10);
7048
 
        TEST_EQ (lineno, 1);
7049
 
        nih_free (err);
7050
 
 
7051
6405
 
7052
6406
        /* Check that an oom stanza with an overly small argument results
7053
6407
         * in a syntax error.
7057
6411
 
7058
6412
        pos = 0;
7059
6413
        lineno = 1;
7060
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
6414
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7061
6415
 
7062
6416
        TEST_EQ_P (job, NULL);
7063
6417
 
7067
6421
        TEST_EQ (lineno, 1);
7068
6422
        nih_free (err);
7069
6423
 
7070
 
        TEST_FEATURE ("with overly small score argument");
7071
 
        strcpy (buf, "oom score -1200\n");
7072
 
 
7073
 
        pos = 0;
7074
 
        lineno = 1;
7075
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
7076
 
 
7077
 
        TEST_EQ_P (job, NULL);
7078
 
 
7079
 
        err = nih_error_get ();
7080
 
        TEST_EQ (err->number, PARSE_ILLEGAL_OOM);
7081
 
        TEST_EQ (pos, 10);
7082
 
        TEST_EQ (lineno, 1);
7083
 
        nih_free (err);
7084
 
 
7085
6424
 
7086
6425
        /* Check that an oom stanza with a non-integer argument results
7087
6426
         * in a syntax error.
7091
6430
 
7092
6431
        pos = 0;
7093
6432
        lineno = 1;
7094
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
6433
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7095
6434
 
7096
6435
        TEST_EQ_P (job, NULL);
7097
6436
 
7101
6440
        TEST_EQ (lineno, 1);
7102
6441
        nih_free (err);
7103
6442
 
7104
 
        TEST_FEATURE ("with non-integer score argument");
7105
 
        strcpy (buf, "oom score foo\n");
7106
 
 
7107
 
        pos = 0;
7108
 
        lineno = 1;
7109
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
7110
 
 
7111
 
        TEST_EQ_P (job, NULL);
7112
 
 
7113
 
        err = nih_error_get ();
7114
 
        TEST_EQ (err->number, PARSE_ILLEGAL_OOM);
7115
 
        TEST_EQ (pos, 10);
7116
 
        TEST_EQ (lineno, 1);
7117
 
        nih_free (err);
7118
 
 
7119
6443
 
7120
6444
        /* Check that an oom stanza with a partially numeric argument
7121
6445
         * results in a syntax error.
7125
6449
 
7126
6450
        pos = 0;
7127
6451
        lineno = 1;
7128
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
6452
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7129
6453
 
7130
6454
        TEST_EQ_P (job, NULL);
7131
6455
 
7135
6459
        TEST_EQ (lineno, 1);
7136
6460
        nih_free (err);
7137
6461
 
7138
 
        TEST_FEATURE ("with alphanumeric score argument");
7139
 
        strcpy (buf, "oom score 12foo\n");
7140
 
 
7141
 
        pos = 0;
7142
 
        lineno = 1;
7143
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
7144
 
 
7145
 
        TEST_EQ_P (job, NULL);
7146
 
 
7147
 
        err = nih_error_get ();
7148
 
        TEST_EQ (err->number, PARSE_ILLEGAL_OOM);
7149
 
        TEST_EQ (pos, 10);
7150
 
        TEST_EQ (lineno, 1);
7151
 
        nih_free (err);
7152
 
 
7153
6462
 
7154
6463
        /* Check that an oom stanza with a priority but with an extra
7155
6464
         * argument afterwards results in a syntax error.
7159
6468
 
7160
6469
        pos = 0;
7161
6470
        lineno = 1;
7162
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
6471
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7163
6472
 
7164
6473
        TEST_EQ_P (job, NULL);
7165
6474
 
7168
6477
        TEST_EQ (pos, 7);
7169
6478
        TEST_EQ (lineno, 1);
7170
6479
        nih_free (err);
7171
 
 
7172
 
        TEST_FEATURE ("with extra score argument");
7173
 
        strcpy (buf, "oom score 500 foo\n");
7174
 
 
7175
 
        pos = 0;
7176
 
        lineno = 1;
7177
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
7178
 
 
7179
 
        TEST_EQ_P (job, NULL);
7180
 
 
7181
 
        err = nih_error_get ();
7182
 
        TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
7183
 
        TEST_EQ (pos, 14);
7184
 
        TEST_EQ (lineno, 1);
7185
 
        nih_free (err);
7186
6480
}
7187
6481
 
7188
6482
void
7203
6497
        TEST_ALLOC_FAIL {
7204
6498
                pos = 0;
7205
6499
                lineno = 1;
7206
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6500
                job = parse_job (NULL, "test", buf, strlen (buf),
7207
6501
                                 &pos, &lineno);
7208
6502
 
7209
6503
                if (test_alloc_failed) {
7237
6531
        TEST_ALLOC_FAIL {
7238
6532
                pos = 0;
7239
6533
                lineno = 1;
7240
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6534
                job = parse_job (NULL, "test", buf, strlen (buf),
7241
6535
                                 &pos, &lineno);
7242
6536
 
7243
6537
                if (test_alloc_failed) {
7271
6565
        TEST_ALLOC_FAIL {
7272
6566
                pos = 0;
7273
6567
                lineno = 1;
7274
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6568
                job = parse_job (NULL, "test", buf, strlen (buf),
7275
6569
                                 &pos, &lineno);
7276
6570
 
7277
6571
                if (test_alloc_failed) {
7305
6599
        TEST_ALLOC_FAIL {
7306
6600
                pos = 0;
7307
6601
                lineno = 1;
7308
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6602
                job = parse_job (NULL, "test", buf, strlen (buf),
7309
6603
                                 &pos, &lineno);
7310
6604
 
7311
6605
                if (test_alloc_failed) {
7339
6633
        TEST_ALLOC_FAIL {
7340
6634
                pos = 0;
7341
6635
                lineno = 1;
7342
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6636
                job = parse_job (NULL, "test", buf, strlen (buf),
7343
6637
                                 &pos, &lineno);
7344
6638
 
7345
6639
                if (test_alloc_failed) {
7374
6668
        TEST_ALLOC_FAIL {
7375
6669
                pos = 0;
7376
6670
                lineno = 1;
7377
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6671
                job = parse_job (NULL, "test", buf, strlen (buf),
7378
6672
                                 &pos, &lineno);
7379
6673
 
7380
6674
                if (test_alloc_failed) {
7409
6703
        TEST_ALLOC_FAIL {
7410
6704
                pos = 0;
7411
6705
                lineno = 1;
7412
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6706
                job = parse_job (NULL, "test", buf, strlen (buf),
7413
6707
                                 &pos, &lineno);
7414
6708
 
7415
6709
                if (test_alloc_failed) {
7443
6737
        TEST_ALLOC_FAIL {
7444
6738
                pos = 0;
7445
6739
                lineno = 1;
7446
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6740
                job = parse_job (NULL, "test", buf, strlen (buf),
7447
6741
                                 &pos, &lineno);
7448
6742
 
7449
6743
                if (test_alloc_failed) {
7478
6772
        TEST_ALLOC_FAIL {
7479
6773
                pos = 0;
7480
6774
                lineno = 1;
7481
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6775
                job = parse_job (NULL, "test", buf, strlen (buf),
7482
6776
                                 &pos, &lineno);
7483
6777
 
7484
6778
                if (test_alloc_failed) {
7512
6806
        TEST_ALLOC_FAIL {
7513
6807
                pos = 0;
7514
6808
                lineno = 1;
7515
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6809
                job = parse_job (NULL, "test", buf, strlen (buf),
7516
6810
                                 &pos, &lineno);
7517
6811
 
7518
6812
                if (test_alloc_failed) {
7546
6840
        TEST_ALLOC_FAIL {
7547
6841
                pos = 0;
7548
6842
                lineno = 1;
7549
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6843
                job = parse_job (NULL, "test", buf, strlen (buf),
7550
6844
                                 &pos, &lineno);
7551
6845
 
7552
6846
                if (test_alloc_failed) {
7580
6874
        TEST_ALLOC_FAIL {
7581
6875
                pos = 0;
7582
6876
                lineno = 1;
7583
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6877
                job = parse_job (NULL, "test", buf, strlen (buf),
7584
6878
                                 &pos, &lineno);
7585
6879
 
7586
6880
                if (test_alloc_failed) {
7615
6909
        TEST_ALLOC_FAIL {
7616
6910
                pos = 0;
7617
6911
                lineno = 1;
7618
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6912
                job = parse_job (NULL, "test", buf, strlen (buf),
7619
6913
                                 &pos, &lineno);
7620
6914
 
7621
6915
                if (test_alloc_failed) {
7649
6943
        TEST_ALLOC_FAIL {
7650
6944
                pos = 0;
7651
6945
                lineno = 1;
7652
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6946
                job = parse_job (NULL, "test", buf, strlen (buf),
7653
6947
                                 &pos, &lineno);
7654
6948
 
7655
6949
                if (test_alloc_failed) {
7685
6979
        TEST_ALLOC_FAIL {
7686
6980
                pos = 0;
7687
6981
                lineno = 1;
7688
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
6982
                job = parse_job (NULL, "test", buf, strlen (buf),
7689
6983
                                 &pos, &lineno);
7690
6984
 
7691
6985
                if (test_alloc_failed) {
7724
7018
        TEST_ALLOC_FAIL {
7725
7019
                pos = 0;
7726
7020
                lineno = 1;
7727
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
7021
                job = parse_job (NULL, "test", buf, strlen (buf),
7728
7022
                                 &pos, &lineno);
7729
7023
 
7730
7024
                if (test_alloc_failed) {
7759
7053
        TEST_ALLOC_FAIL {
7760
7054
                pos = 0;
7761
7055
                lineno = 1;
7762
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
7056
                job = parse_job (NULL, "test", buf, strlen (buf),
7763
7057
                                 &pos, &lineno);
7764
7058
 
7765
7059
                if (test_alloc_failed) {
7794
7088
        TEST_ALLOC_FAIL {
7795
7089
                pos = 0;
7796
7090
                lineno = 1;
7797
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
7091
                job = parse_job (NULL, "test", buf, strlen (buf),
7798
7092
                                 &pos, &lineno);
7799
7093
 
7800
7094
                if (test_alloc_failed) {
7828
7122
 
7829
7123
        pos = 0;
7830
7124
        lineno = 1;
7831
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7125
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7832
7126
 
7833
7127
        TEST_EQ_P (job, NULL);
7834
7128
 
7847
7141
 
7848
7142
        pos = 0;
7849
7143
        lineno = 1;
7850
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7144
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7851
7145
 
7852
7146
        TEST_EQ_P (job, NULL);
7853
7147
 
7866
7160
 
7867
7161
        pos = 0;
7868
7162
        lineno = 1;
7869
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7163
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7870
7164
 
7871
7165
        TEST_EQ_P (job, NULL);
7872
7166
 
7885
7179
 
7886
7180
        pos = 0;
7887
7181
        lineno = 1;
7888
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7182
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7889
7183
 
7890
7184
        TEST_EQ_P (job, NULL);
7891
7185
 
7904
7198
 
7905
7199
        pos = 0;
7906
7200
        lineno = 1;
7907
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7201
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7908
7202
 
7909
7203
        TEST_EQ_P (job, NULL);
7910
7204
 
7923
7217
 
7924
7218
        pos = 0;
7925
7219
        lineno = 1;
7926
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7220
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7927
7221
 
7928
7222
        TEST_EQ_P (job, NULL);
7929
7223
 
7942
7236
 
7943
7237
        pos = 0;
7944
7238
        lineno = 1;
7945
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7239
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7946
7240
 
7947
7241
        TEST_EQ_P (job, NULL);
7948
7242
 
7961
7255
 
7962
7256
        pos = 0;
7963
7257
        lineno = 1;
7964
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7258
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7965
7259
 
7966
7260
        TEST_EQ_P (job, NULL);
7967
7261
 
7980
7274
 
7981
7275
        pos = 0;
7982
7276
        lineno = 1;
7983
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7277
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
7984
7278
 
7985
7279
        TEST_EQ_P (job, NULL);
7986
7280
 
7999
7293
 
8000
7294
        pos = 0;
8001
7295
        lineno = 1;
8002
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7296
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
8003
7297
 
8004
7298
        TEST_EQ_P (job, NULL);
8005
7299
 
8018
7312
 
8019
7313
        pos = 0;
8020
7314
        lineno = 1;
8021
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7315
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
8022
7316
 
8023
7317
        TEST_EQ_P (job, NULL);
8024
7318
 
8048
7342
        TEST_ALLOC_FAIL {
8049
7343
                pos = 0;
8050
7344
                lineno = 1;
8051
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
7345
                job = parse_job (NULL, "test", buf, strlen (buf),
8052
7346
                                 &pos, &lineno);
8053
7347
 
8054
7348
                if (test_alloc_failed) {
8082
7376
        TEST_ALLOC_FAIL {
8083
7377
                pos = 0;
8084
7378
                lineno = 1;
8085
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
7379
                job = parse_job (NULL, "test", buf, strlen (buf),
8086
7380
                                 &pos, &lineno);
8087
7381
 
8088
7382
                if (test_alloc_failed) {
8115
7409
 
8116
7410
        pos = 0;
8117
7411
        lineno = 1;
8118
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7412
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
8119
7413
 
8120
7414
        TEST_EQ_P (job, NULL);
8121
7415
 
8134
7428
 
8135
7429
        pos = 0;
8136
7430
        lineno = 1;
8137
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7431
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
8138
7432
 
8139
7433
        TEST_EQ_P (job, NULL);
8140
7434
 
8164
7458
        TEST_ALLOC_FAIL {
8165
7459
                pos = 0;
8166
7460
                lineno = 1;
8167
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
7461
                job = parse_job (NULL, "test", buf, strlen (buf),
8168
7462
                                 &pos, &lineno);
8169
7463
 
8170
7464
                if (test_alloc_failed) {
8198
7492
        TEST_ALLOC_FAIL {
8199
7493
                pos = 0;
8200
7494
                lineno = 1;
8201
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
 
7495
                job = parse_job (NULL, "test", buf, strlen (buf),
8202
7496
                                 &pos, &lineno);
8203
7497
 
8204
7498
                if (test_alloc_failed) {
8231
7525
 
8232
7526
        pos = 0;
8233
7527
        lineno = 1;
8234
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7528
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
8235
7529
 
8236
7530
        TEST_EQ_P (job, NULL);
8237
7531
 
8250
7544
 
8251
7545
        pos = 0;
8252
7546
        lineno = 1;
8253
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
 
7547
        job = parse_job (NULL, "test", buf, strlen (buf), &pos, &lineno);
8254
7548
 
8255
7549
        TEST_EQ_P (job, NULL);
8256
7550
 
8261
7555
        nih_free (err);
8262
7556
}
8263
7557
 
8264
 
void
8265
 
test_stanza_setuid (void)
8266
 
{
8267
 
        JobClass*job;
8268
 
        NihError *err;
8269
 
        size_t    pos, lineno;
8270
 
        char      buf[1024];
8271
 
 
8272
 
        TEST_FUNCTION ("stanza_setuid");
8273
 
 
8274
 
        /* Check that a setuid stanza with an argument results in it
8275
 
         * being stored in the job.
8276
 
         */
8277
 
        TEST_FEATURE ("with single argument");
8278
 
        strcpy (buf, "setuid www-data\n");
8279
 
 
8280
 
        TEST_ALLOC_FAIL {
8281
 
                pos = 0;
8282
 
                lineno = 1;
8283
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
8284
 
                                 &pos, &lineno);
8285
 
 
8286
 
                if (test_alloc_failed) {
8287
 
                        TEST_EQ_P (job, NULL);
8288
 
 
8289
 
                        err = nih_error_get ();
8290
 
                        TEST_EQ (err->number, ENOMEM);
8291
 
                        nih_free (err);
8292
 
 
8293
 
                        continue;
8294
 
                }
8295
 
 
8296
 
                TEST_EQ (pos, strlen (buf));
8297
 
                TEST_EQ (lineno, 2);
8298
 
 
8299
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
8300
 
 
8301
 
                TEST_ALLOC_PARENT (job->setuid, job);
8302
 
                TEST_EQ_STR (job->setuid, "www-data");
8303
 
 
8304
 
                nih_free (job);
8305
 
        }
8306
 
 
8307
 
 
8308
 
        /* Check that the last of multiple setuid stanzas is used.
8309
 
         */
8310
 
        TEST_FEATURE ("with multiple stanzas");
8311
 
        strcpy (buf, "setuid www-data\n");
8312
 
        strcat (buf, "setuid pulse\n");
8313
 
 
8314
 
        TEST_ALLOC_FAIL {
8315
 
                pos = 0;
8316
 
                lineno = 1;
8317
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
8318
 
                                 &pos, &lineno);
8319
 
 
8320
 
                if (test_alloc_failed) {
8321
 
                        TEST_EQ_P (job, NULL);
8322
 
 
8323
 
                        err = nih_error_get ();
8324
 
                        TEST_EQ (err->number, ENOMEM);
8325
 
                        nih_free (err);
8326
 
 
8327
 
                        continue;
8328
 
                }
8329
 
 
8330
 
                TEST_EQ (pos, strlen (buf));
8331
 
                TEST_EQ (lineno, 3);
8332
 
 
8333
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
8334
 
 
8335
 
                TEST_ALLOC_PARENT (job->setuid, job);
8336
 
                TEST_EQ_STR (job->setuid, "pulse");
8337
 
 
8338
 
                nih_free (job);
8339
 
        }
8340
 
 
8341
 
 
8342
 
        /* Check that a setuid stanza without an argument results in
8343
 
         * a syntax error.
8344
 
         */
8345
 
        TEST_FEATURE ("with missing argument");
8346
 
        strcpy (buf, "setuid\n");
8347
 
 
8348
 
        pos = 0;
8349
 
        lineno = 1;
8350
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
8351
 
 
8352
 
        TEST_EQ_P (job, NULL);
8353
 
 
8354
 
        err = nih_error_get ();
8355
 
        TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
8356
 
        TEST_EQ (pos, 6);
8357
 
        TEST_EQ (lineno, 1);
8358
 
        nih_free (err);
8359
 
 
8360
 
 
8361
 
        /* Check that a setuid stanza with an extra second argument
8362
 
         * results in a syntax error.
8363
 
         */
8364
 
        TEST_FEATURE ("with extra argument");
8365
 
        strcpy (buf, "setuid www-data foo\n");
8366
 
 
8367
 
        pos = 0;
8368
 
        lineno = 1;
8369
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
8370
 
 
8371
 
        TEST_EQ_P (job, NULL);
8372
 
 
8373
 
        err = nih_error_get ();
8374
 
        TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
8375
 
        TEST_EQ (pos, 16);
8376
 
        TEST_EQ (lineno, 1);
8377
 
        nih_free (err);
8378
 
}
8379
 
 
8380
 
void
8381
 
test_stanza_setgid (void)
8382
 
{
8383
 
        JobClass*job;
8384
 
        NihError *err;
8385
 
        size_t    pos, lineno;
8386
 
        char      buf[1024];
8387
 
 
8388
 
        TEST_FUNCTION ("stanza_setgid");
8389
 
 
8390
 
        /* Check that a setgid stanza with an argument results in it
8391
 
         * being stored in the job.
8392
 
         */
8393
 
        TEST_FEATURE ("with single argument");
8394
 
        strcpy (buf, "setgid kvm\n");
8395
 
 
8396
 
        TEST_ALLOC_FAIL {
8397
 
                pos = 0;
8398
 
                lineno = 1;
8399
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
8400
 
                                 &pos, &lineno);
8401
 
 
8402
 
                if (test_alloc_failed) {
8403
 
                        TEST_EQ_P (job, NULL);
8404
 
 
8405
 
                        err = nih_error_get ();
8406
 
                        TEST_EQ (err->number, ENOMEM);
8407
 
                        nih_free (err);
8408
 
 
8409
 
                        continue;
8410
 
                }
8411
 
 
8412
 
                TEST_EQ (pos, strlen (buf));
8413
 
                TEST_EQ (lineno, 2);
8414
 
 
8415
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
8416
 
 
8417
 
                TEST_ALLOC_PARENT (job->setgid, job);
8418
 
                TEST_EQ_STR (job->setgid, "kvm");
8419
 
 
8420
 
                nih_free (job);
8421
 
        }
8422
 
 
8423
 
 
8424
 
        /* Check that the last of multiple setgid stanzas is used.
8425
 
         */
8426
 
        TEST_FEATURE ("with multiple stanzas");
8427
 
        strcpy (buf, "setgid kvm\n");
8428
 
        strcat (buf, "setgid fuse\n");
8429
 
 
8430
 
        TEST_ALLOC_FAIL {
8431
 
                pos = 0;
8432
 
                lineno = 1;
8433
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
8434
 
                                 &pos, &lineno);
8435
 
 
8436
 
                if (test_alloc_failed) {
8437
 
                        TEST_EQ_P (job, NULL);
8438
 
 
8439
 
                        err = nih_error_get ();
8440
 
                        TEST_EQ (err->number, ENOMEM);
8441
 
                        nih_free (err);
8442
 
 
8443
 
                        continue;
8444
 
                }
8445
 
 
8446
 
                TEST_EQ (pos, strlen (buf));
8447
 
                TEST_EQ (lineno, 3);
8448
 
 
8449
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
8450
 
 
8451
 
                TEST_ALLOC_PARENT (job->setgid, job);
8452
 
                TEST_EQ_STR (job->setgid, "fuse");
8453
 
 
8454
 
                nih_free (job);
8455
 
        }
8456
 
 
8457
 
 
8458
 
        /* Check that a setgid stanza without an argument results in
8459
 
         * a syntax error.
8460
 
         */
8461
 
        TEST_FEATURE ("with missing argument");
8462
 
        strcpy (buf, "setgid\n");
8463
 
 
8464
 
        pos = 0;
8465
 
        lineno = 1;
8466
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
8467
 
 
8468
 
        TEST_EQ_P (job, NULL);
8469
 
 
8470
 
        err = nih_error_get ();
8471
 
        TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
8472
 
        TEST_EQ (pos, 6);
8473
 
        TEST_EQ (lineno, 1);
8474
 
        nih_free (err);
8475
 
 
8476
 
 
8477
 
        /* Check that a setgid stanza with an extra second argument
8478
 
         * results in a syntax error.
8479
 
         */
8480
 
        TEST_FEATURE ("with extra argument");
8481
 
        strcpy (buf, "setgid kvm foo\n");
8482
 
 
8483
 
        pos = 0;
8484
 
        lineno = 1;
8485
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
8486
 
 
8487
 
        TEST_EQ_P (job, NULL);
8488
 
 
8489
 
        err = nih_error_get ();
8490
 
        TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
8491
 
        TEST_EQ (pos, 11);
8492
 
        TEST_EQ (lineno, 1);
8493
 
        nih_free (err);
8494
 
}
8495
 
 
8496
 
void
8497
 
test_stanza_usage (void)
8498
 
{
8499
 
        JobClass*job;
8500
 
        NihError *err;
8501
 
        size_t    pos, lineno;
8502
 
        char      buf[1024];
8503
 
 
8504
 
        TEST_FUNCTION ("stanza_usage");
8505
 
 
8506
 
        /* Check that a usage stanza with an argument results in it
8507
 
         * being stored in the job.
8508
 
         */
8509
 
        TEST_FEATURE ("with single argument");
8510
 
        strcpy (buf, "usage \"stanza usage test message\"\n");
8511
 
 
8512
 
        TEST_ALLOC_FAIL {
8513
 
                pos = 0;
8514
 
                lineno = 1;
8515
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
8516
 
                                 &pos, &lineno);
8517
 
 
8518
 
                if (test_alloc_failed) {
8519
 
                        TEST_EQ_P (job, NULL);
8520
 
 
8521
 
                        err = nih_error_get ();
8522
 
                        TEST_EQ (err->number, ENOMEM);
8523
 
                        nih_free (err);
8524
 
 
8525
 
                        continue;
8526
 
                }
8527
 
 
8528
 
                TEST_EQ (pos, strlen (buf));
8529
 
                TEST_EQ (lineno, 2);
8530
 
 
8531
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
8532
 
 
8533
 
                TEST_ALLOC_PARENT (job->usage, job);
8534
 
                TEST_EQ_STR (job->usage, "stanza usage test message");
8535
 
 
8536
 
                nih_free (job);
8537
 
        }
8538
 
 
8539
 
 
8540
 
        /* Check that the last of multiple usage stanzas is used.
8541
 
         */
8542
 
        TEST_FEATURE ("with multiple stanzas");
8543
 
        strcpy (buf, "usage \"stanza usage original\"\n");
8544
 
        strcat (buf, "usage \"stanza usage test message\"\n");
8545
 
 
8546
 
        TEST_ALLOC_FAIL {
8547
 
                pos = 0;
8548
 
                lineno = 1;
8549
 
                job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf),
8550
 
                                 &pos, &lineno);
8551
 
 
8552
 
                if (test_alloc_failed) {
8553
 
                        TEST_EQ_P (job, NULL);
8554
 
 
8555
 
                        err = nih_error_get ();
8556
 
                        TEST_EQ (err->number, ENOMEM);
8557
 
                        nih_free (err);
8558
 
 
8559
 
                        continue;
8560
 
                }
8561
 
 
8562
 
                TEST_EQ (pos, strlen (buf));
8563
 
                TEST_EQ (lineno, 3);
8564
 
 
8565
 
                TEST_ALLOC_SIZE (job, sizeof (JobClass));
8566
 
 
8567
 
                TEST_ALLOC_PARENT (job->usage, job);
8568
 
                TEST_EQ_STR (job->usage, "stanza usage test message");
8569
 
 
8570
 
                nih_free (job);
8571
 
        }
8572
 
 
8573
 
 
8574
 
        /* Check that a usage stanza without an argument results in
8575
 
         * a syntax error.
8576
 
         */
8577
 
        TEST_FEATURE ("with missing argument");
8578
 
        strcpy (buf, "usage\n");
8579
 
 
8580
 
        pos = 0;
8581
 
        lineno = 1;
8582
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
8583
 
 
8584
 
        TEST_EQ_P (job, NULL);
8585
 
 
8586
 
        err = nih_error_get ();
8587
 
        TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
8588
 
        TEST_EQ (pos, 5);
8589
 
        TEST_EQ (lineno, 1);
8590
 
        nih_free (err);
8591
 
 
8592
 
 
8593
 
        /* Check that a usage stanza with an extra second argument
8594
 
         * results in a syntax error.
8595
 
         */
8596
 
        TEST_FEATURE ("with extra argument");
8597
 
        strcpy (buf, "usage stanza usage test message\n");
8598
 
 
8599
 
        pos = 0;
8600
 
        lineno = 1;
8601
 
        job = parse_job (NULL, NULL, NULL, "test", buf, strlen (buf), &pos, &lineno);
8602
 
 
8603
 
        TEST_EQ_P (job, NULL);
8604
 
 
8605
 
        err = nih_error_get ();
8606
 
        TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN);
8607
 
        TEST_EQ (pos, 13);
8608
 
        TEST_EQ (lineno, 1);
8609
 
        nih_free (err);
8610
 
}
8611
 
 
8612
7558
int
8613
7559
main (int   argc,
8614
7560
      char *argv[])
8615
7561
{
8616
 
        /* run tests in legacy (pre-session support) mode */
8617
 
        setenv ("UPSTART_NO_SESSIONS", "1", 1);
8618
 
 
8619
7562
        test_parse_job ();
8620
7563
 
8621
7564
        test_stanza_instance ();
8630
7573
        test_stanza_start ();
8631
7574
        test_stanza_stop ();
8632
7575
        test_stanza_emits ();
8633
 
        test_stanza_manual ();
8634
7576
 
8635
7577
        test_stanza_exec ();
8636
7578
        test_stanza_script ();
8637
 
        test_stanza_apparmor ();
8638
7579
        test_stanza_pre_start ();
8639
7580
        test_stanza_post_start ();
8640
7581
        test_stanza_pre_stop ();
8648
7589
        test_stanza_respawn ();
8649
7590
        test_stanza_normal ();
8650
7591
 
 
7592
        test_stanza_session ();
8651
7593
        test_stanza_console ();
8652
7594
 
8653
7595
        test_stanza_umask ();
8656
7598
        test_stanza_limit ();
8657
7599
        test_stanza_chroot ();
8658
7600
        test_stanza_chdir ();
8659
 
        test_stanza_setuid ();
8660
 
        test_stanza_setgid ();
8661
 
        test_stanza_usage ();
8662
7601
 
8663
7602
        return 0;
8664
7603
}