Merge lp:~jamesodhunt/upstart/add-race-checking-tests into lp:upstart

Proposed by Dimitri John Ledkov
Status: Rejected
Rejected by: James Hunt
Proposed branch: lp:~jamesodhunt/upstart/add-race-checking-tests
Merge into: lp:upstart
Diff against target: 341 lines (+270/-7)
3 files modified
init/job_process.c (+1/-4)
init/job_process.h (+4/-0)
init/tests/test_job_process.c (+265/-3)
To merge this branch: bzr merge lp:~jamesodhunt/upstart/add-race-checking-tests
Reviewer Review Type Date Requested Status
Upstart Reviewers Pending
Review via email: mp+225963@code.launchpad.net
To post a comment you must log in.
1643. By James Hunt

* Sync with lp:upstart.

1644. By James Hunt

latest

Revision history for this message
James Hunt (jamesodhunt) wrote :

Unmerged revisions

1644. By James Hunt

latest

1643. By James Hunt

* Sync with lp:upstart.

1642. By James Hunt

* latest.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'init/job_process.c'
--- init/job_process.c 2014-07-03 08:59:30 +0000
+++ init/job_process.c 2014-07-08 17:02:18 +0000
@@ -111,9 +111,6 @@
111int disable_respawn = FALSE;111int disable_respawn = FALSE;
112112
113/* Prototypes for static functions */113/* Prototypes for static functions */
114static void job_process_error_abort (int fd, JobProcessErrorType type,
115 int arg)
116 __attribute__ ((noreturn));
117static void job_process_remap_fd (int *fd, int reserved_fd, int error_fd);114static void job_process_remap_fd (int *fd, int reserved_fd, int error_fd);
118115
119/**116/**
@@ -983,7 +980,7 @@
983 *980 *
984 * This function calls the exit() system call, so never returns.981 * This function calls the exit() system call, so never returns.
985 **/982 **/
986static void983void
987job_process_error_abort (int fd,984job_process_error_abort (int fd,
988 JobProcessErrorType type,985 JobProcessErrorType type,
989 int arg)986 int arg)
990987
=== modified file 'init/job_process.h'
--- init/job_process.h 2014-06-02 20:29:33 +0000
+++ init/job_process.h 2014-07-08 17:02:18 +0000
@@ -194,6 +194,10 @@
194194
195void job_process_error_handler (const char *buf, size_t len);195void job_process_error_handler (const char *buf, size_t len);
196196
197void job_process_error_abort (int fd, JobProcessErrorType type,
198 int arg)
199 __attribute__ ((noreturn));
200
197NIH_END_EXTERN201NIH_END_EXTERN
198202
199#endif /* INIT_JOB_PROCESS_H */203#endif /* INIT_JOB_PROCESS_H */
200204
=== modified file 'init/tests/test_job_process.c'
--- init/tests/test_job_process.c 2014-07-07 10:15:25 +0000
+++ init/tests/test_job_process.c 2014-07-08 17:02:18 +0000
@@ -5488,6 +5488,8 @@
5488 char dirname[PATH_MAX];5488 char dirname[PATH_MAX];
5489 nih_local char *logfile = NULL;5489 nih_local char *logfile = NULL;
5490 int fds[2] = { -1, -1};5490 int fds[2] = { -1, -1};
5491 NihIo *io = NULL;
5492 nih_local NihIoBuffer *buffer= NULL;
54915493
5492 TEST_FILENAME (dirname); 5494 TEST_FILENAME (dirname);
5493 TEST_EQ (mkdir (dirname, 0755), 0);5495 TEST_EQ (mkdir (dirname, 0755), 0);
@@ -8770,13 +8772,269 @@
87708772
8771 fclose (output);8773 fclose (output);
87728774
8775 nih_free (event);
8776 event_poll ();
8777
8778 TEST_RESET_MAIN_LOOP ();
8779
8780 TEST_NE_P (class->process[PROCESS_MAIN], NULL);
8781 TEST_EQ_P (class->process[PROCESS_PRE_START], NULL);
8782 TEST_EQ_P (class->process[PROCESS_POST_START], NULL);
8783 TEST_EQ_P (class->process[PROCESS_PRE_STOP], NULL);
8784 TEST_EQ_P (class->process[PROCESS_POST_STOP], NULL);
8785 TEST_EQ_P (class->process[PROCESS_SECURITY], NULL);
8786
8787 /* FIXME */
8788#if 0
8789 /************************************************************/
8790 /* Ensure that if a child is setup successfully and then exits
8791 * before the main loop detects the child fd has closed (due to
8792 * the child calling execvp()), that the state is correct.
8793 */
8794 TEST_FEATURE ("with child exit notification before child setup success notification");
8795
8796 job = job_new (class, "");
8797 TEST_NE_P (job, NULL);
8798
8799 job->goal = JOB_START;
8800 job->state = JOB_SPAWNING;
8801
8802 assert0 (pipe (fds));
8803
8804 job->process_data[PROCESS_MAIN] = job_process_data_new (job->process_data,
8805 job, PROCESS_MAIN, fds[0]);
8806 TEST_NE_P (job->process_data[PROCESS_MAIN], NULL);
8807
8808 TEST_NE_P (class->process[PROCESS_MAIN], NULL);
8809 TEST_EQ_P (class->process[PROCESS_PRE_START], NULL);
8810 TEST_EQ_P (class->process[PROCESS_POST_START], NULL);
8811 TEST_EQ_P (class->process[PROCESS_PRE_STOP], NULL);
8812 TEST_EQ_P (class->process[PROCESS_POST_STOP], NULL);
8813 TEST_EQ_P (class->process[PROCESS_SECURITY], NULL);
8814
8815 TEST_CHILD (job->pid[PROCESS_MAIN]) {
8816 close (fds[0]);
8817
8818 nih_io_set_cloexec (fds[1]);
8819
8820 execl ("/bin/true", "/bin/true", NULL);
8821 }
8822 close (fds[1]);
8823
8824 TEST_FREE_TAG (job);
8825
8826 job_process_handler (NULL, job->pid[PROCESS_MAIN],
8827 NIH_CHILD_EXITED, 0);
8828
8829 TEST_NOT_FREE (job);
8830
8831 /* goal should not change until the IO handlers have had a
8832 * chance to run.
8833 */
8834 TEST_EQ (job->goal, JOB_START);
8835
8836 TEST_EQ (job->state, JOB_SPAWNED);
8837 TEST_NE_P (job->process_data[PROCESS_MAIN], NULL);
8838
8839 TEST_TRUE (job->process_data[PROCESS_MAIN]->valid);
8840 TEST_EQ (job->process_data[PROCESS_MAIN]->job_process_fd, fds[0]);
8841 TEST_EQ (job->process_data[PROCESS_MAIN]->shell_fd, -1);
8842 TEST_EQ_P (job->process_data[PROCESS_MAIN]->script, NULL);
8843 TEST_EQ (job->process_data[PROCESS_MAIN]->status, 0);
8844
8845 close (fds[0]);
8846 nih_free (job);
8847
8848 TEST_RESET_MAIN_LOOP ();
8849
8850 /************************************************************/
8851 /* Ensure that if a child failed to be setup and then exits
8852 * before the main loop detects the child fd has data to read
8853 * that the state is correct.
8854 */
8855 TEST_FEATURE ("with child exit notification before child setup failure notification");
8856
8857 job = job_new (class, "");
8858 TEST_NE_P (job, NULL);
8859
8860 job->goal = JOB_START;
8861 job->state = JOB_SPAWNING;
8862
8863 assert0 (pipe (fds));
8864
8865 job->process_data[PROCESS_MAIN] = job_process_data_new (job->process_data,
8866 job, PROCESS_MAIN, fds[0]);
8867 TEST_NE_P (job->process_data[PROCESS_MAIN], NULL);
8868 TEST_EQ (job->process_data[PROCESS_MAIN]->job_process_fd, fds[0]);
8869 TEST_EQ (job->process_data[PROCESS_MAIN]->process, PROCESS_MAIN);
8870
8871 TEST_CHILD (job->pid[PROCESS_MAIN]) {
8872 close (fds[0]);
8873
8874 nih_error_raise_no_memory ();
8875 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_CGROUP_SETUP, 0);
8876 }
8877 close (fds[1]);
8878
8879 TEST_FREE_TAG (job);
8880
8881 job_process_handler (NULL, job->pid[PROCESS_MAIN],
8882 NIH_CHILD_DUMPED, SIGABRT);
8883
8884 TEST_NOT_FREE (job);
8885
8886 /* goal should not change until the IO handlers have had a
8887 * chance to run.
8888 */
8889 TEST_EQ (job->goal, JOB_START);
8890
8891 TEST_EQ (job->state, JOB_SPAWNED);
8892 TEST_NE_P (job->process_data[PROCESS_MAIN], NULL);
8893
8894 /* Still valid because the IO handlers haven't fired yet */
8895 TEST_TRUE (job->process_data[PROCESS_MAIN]->valid);
8896 TEST_EQ (job->process_data[PROCESS_MAIN]->job_process_fd, fds[0]);
8897
8898 TEST_EQ (job->process_data[PROCESS_MAIN]->shell_fd, -1);
8899 TEST_EQ_P (job->process_data[PROCESS_MAIN]->script, NULL);
8900 TEST_NE (job->process_data[PROCESS_MAIN]->status, 0);
8901
8902 /* slurp - don't care about content */
8903 buffer = read_from_fd (NULL, fds[0]);
8904 close (fds[0]);
8905
8906 nih_free (job);
8907
8908 TEST_RESET_MAIN_LOOP ();
8909
8910 /************************************************************/
8911 TEST_FEATURE ("with child setup success notification before child exit notification");
8912
8913 job = job_new (class, "");
8914 TEST_NE_P (job, NULL);
8915
8916 job->goal = JOB_START;
8917 job->state = JOB_SPAWNING;
8918
8919 assert0 (pipe (fds));
8920
8921 job->process_data[PROCESS_MAIN] = job_process_data_new (job->process_data,
8922 job, PROCESS_MAIN, fds[0]);
8923 TEST_NE_P (job->process_data[PROCESS_MAIN], NULL);
8924 TEST_EQ (job->process_data[PROCESS_MAIN]->job_process_fd, fds[0]);
8925 TEST_EQ (job->process_data[PROCESS_MAIN]->process, PROCESS_MAIN);
8926
8927 io = nih_io_reopen (job->process_data[PROCESS_MAIN],
8928 fds[0],
8929 NIH_IO_STREAM,
8930 (NihIoReader)job_process_child_reader,
8931 (NihIoCloseHandler)job_process_close_handler,
8932 NULL,
8933 job->process_data[PROCESS_MAIN]);
8934 TEST_NE_P (io, NULL);
8935
8936 TEST_CHILD (job->pid[PROCESS_MAIN]) {
8937 close (fds[0]);
8938
8939 nih_io_set_cloexec (fds[1]);
8940
8941 execl ("/bin/true", "/bin/true", NULL);
8942 }
8943 close (fds[1]);
8944 pid = job->pid[PROCESS_MAIN];
8945
8946 job_process_close_handler (job->process_data[PROCESS_MAIN], io);
8947
8948 TEST_EQ (job->goal, JOB_START);
8949 TEST_EQ (job->state, JOB_SPAWNED);
8950 TEST_NE_P (job->process_data[PROCESS_MAIN], NULL);
8951
8952 /* Invalid because the IO handlers have now run */
8953 TEST_FALSE (job->process_data[PROCESS_MAIN]->valid);
8954 TEST_EQ (job->process_data[PROCESS_MAIN]->job_process_fd, -1);
8955
8956 TEST_EQ (job->process_data[PROCESS_MAIN]->shell_fd, -1);
8957 TEST_EQ_P (job->process_data[PROCESS_MAIN]->script, NULL);
8958 TEST_EQ (job->process_data[PROCESS_MAIN]->status, 0);
8959
8960 close (fds[0]);
8961 nih_free (job);
8962
8963 (void)timed_waitpid (pid, 5);
8964
8965 TEST_RESET_MAIN_LOOP ();
8966#endif
8967
8968 /************************************************************/
8969 TEST_FEATURE ("with child setup failure notification before child exit notification");
8970
8971 job = job_new (class, "");
8972 TEST_NE_P (job, NULL);
8973
8974 job->goal = JOB_START;
8975 job->state = JOB_SPAWNING;
8976
8977 assert0 (pipe (fds));
8978
8979 job->process_data[PROCESS_MAIN] = job_process_data_new (job->process_data,
8980 job, PROCESS_MAIN, fds[0]);
8981 TEST_NE_P (job->process_data[PROCESS_MAIN], NULL);
8982 TEST_EQ (job->process_data[PROCESS_MAIN]->job_process_fd, fds[0]);
8983 TEST_EQ (job->process_data[PROCESS_MAIN]->process, PROCESS_MAIN);
8984
8985 /* Can't use job_register_child_handler() as we want the return
8986 * value.
8987 */
8988 io = nih_io_reopen (job->process_data[PROCESS_MAIN],
8989 fds[0],
8990 NIH_IO_STREAM,
8991 (NihIoReader)job_process_child_reader,
8992 (NihIoCloseHandler)job_process_close_handler,
8993 NULL,
8994 job->process_data[PROCESS_MAIN]);
8995 TEST_NE_P (io, NULL);
8996
8997 TEST_CHILD (job->pid[PROCESS_MAIN]) {
8998 close (fds[0]);
8999
9000 nih_error_raise_no_memory ();
9001 job_process_error_abort (fds[1], JOB_PROCESS_ERROR_CGROUP_SETUP, 0);
9002 }
9003 close (fds[1]);
9004
9005 buffer = read_from_fd (NULL, fds[0]);
9006 job_process_child_reader (job->process_data[PROCESS_MAIN],
9007 io, buffer->buf, buffer->len);
9008
9009 TEST_EQ (job->goal, JOB_START);
9010 TEST_EQ (job->state, JOB_SPAWNED);
9011 TEST_NE_P (job->process_data[PROCESS_MAIN], NULL);
9012
9013 /* Invalid because the IO handlers have now run */
9014 TEST_FALSE (job->process_data[PROCESS_MAIN]->valid);
9015 TEST_EQ (job->process_data[PROCESS_MAIN]->job_process_fd, -1);
9016
9017 TEST_EQ (job->process_data[PROCESS_MAIN]->shell_fd, -1);
9018 TEST_EQ_P (job->process_data[PROCESS_MAIN]->script, NULL);
9019 TEST_EQ (job->process_data[PROCESS_MAIN]->shell_fd, -1);
9020
9021 /* Still zero because the process handler hasn't run yet */
9022 TEST_EQ (job->process_data[PROCESS_MAIN]->status, 0);
9023
9024 close (fds[0]);
9025
9026 //waitpid (job->pid[PROCESS_MAIN], &status, 0);
9027
9028 nih_free (job);
9029
9030 TEST_RESET_MAIN_LOOP ();
9031
9032 /************************************************************/
9033
8773 nih_free (class);9034 nih_free (class);
8774 file->job = NULL;9035 file->job = NULL;
8775 nih_free (source);9036 nih_free (source);
87769037
8777 nih_free (event);
8778 event_poll ();
8779
8780 TEST_EQ (rmdir (dirname), 0);9038 TEST_EQ (rmdir (dirname), 0);
8781 TEST_EQ (unsetenv ("UPSTART_LOGDIR"), 0);9039 TEST_EQ (unsetenv ("UPSTART_LOGDIR"), 0);
8782}9040}
@@ -9153,13 +9411,17 @@
9153void9411void
9154run_tests (void)9412run_tests (void)
9155{9413{
9414#if 0
9156 test_start ();9415 test_start ();
9157 test_spawn ();9416 test_spawn ();
9158 test_log_path ();9417 test_log_path ();
9159 test_kill ();9418 test_kill ();
9419#endif
9160 test_handler ();9420 test_handler ();
9421#if 0
9161 test_utmp ();9422 test_utmp ();
9162 test_find ();9423 test_find ();
9424#endif
9163}9425}
91649426
9165/**9427/**

Subscribers

People subscribed via source and target branches