@@ -41,6 +41,7 @@ void offline_enable_test();
4141void xdg_config_test ();
4242void cycles_test ();
4343void svc_arg_test ();
44+ void svc_arg_consumer_test ();
4445
4546int main (int argc, char **argv)
4647{
@@ -57,7 +58,7 @@ int main(int argc, char **argv)
5758 { " before-after2" , before_after2_test }, { " log-via-pipe" , log_via_pipe_test },
5859 { " catlog" , catlog_test }, { " offline-enable" , offline_enable_test },
5960 { " xdg-config" , xdg_config_test }, { " cycles" , cycles_test },
60- { " svc-arg" , svc_arg_test } };
61+ { " svc-arg" , svc_arg_test }, { " svc-arg-consumer " , svc_arg_consumer_test } };
6162 constexpr int num_tests = sizeof (tests) / sizeof (tests[0 ]);
6263
6364 dinit_bindir = " ../.." ;
@@ -998,3 +999,47 @@ void svc_arg_test()
998999 " foo\n " +
9991000 " bar\n " );
10001001}
1002+
1003+ void svc_arg_consumer_test ()
1004+ {
1005+ // Test for using minimal variable substitution in consumer services
1006+ igr_test_setup setup (" svc-arg-consumer" );
1007+
1008+ std::string logged_output_file = setup.prep_output_file (" logged-output" );
1009+ std::string socket_path = setup.prep_socket_path ();
1010+
1011+ // "boot" service brings up "consumer" service and consumer writes its $1 value
1012+ dinit_proc dinit_p;
1013+ dinit_p.start (" svc-arg-consumer" , {" -u" , " -d" , " sd" , " -p" , socket_path, " -q" }, true );
1014+
1015+ nanosleepx (0 , 1000000000u / 10u );
1016+
1017+ igr_assert_eq (read_file_contents (logged_output_file), " producer\n " );
1018+
1019+ // Start and stop the producer for printing output to consumer
1020+ dinitctl_proc dinitctl_p;
1021+ dinitctl_p.start (" svc-arg-consumer" , {" -u" , " -p" , socket_path, " start" , " producer" });
1022+ int status = dinitctl_p.wait_for_term ({1 , 0 }); /* max 1 second */
1023+ igr_assert (status == 0 , " dinitctl did not exit cleanly" );
1024+
1025+ dinitctl_p.start (" svc-arg-consumer" , {" -u" , " -p" , socket_path, " stop" , " producer" });
1026+ status = dinitctl_p.wait_for_term ({1 , 0 }); /* max 1 second */
1027+ igr_assert (status == 0 , " dinitctl did not exit cleanly" );
1028+
1029+ nanosleepx (0 , (1000000000u / 10u ) * 2u );
1030+
1031+ igr_assert_eq (read_file_contents (logged_output_file), " producer\n " " Producing output...\n " );
1032+
1033+ // Another start and stop to make sure that producer is linked to consumer properly
1034+ dinitctl_p.start (" svc-arg-consumer" , {" -u" , " -p" , socket_path, " start" , " producer" });
1035+ status = dinitctl_p.wait_for_term ({1 , 0 }); /* max 1 second */
1036+ igr_assert (status == 0 , " dinitctl did not exit cleanly" );
1037+
1038+ dinitctl_p.start (" svc-arg-consumer" , {" -u" , " -p" , socket_path, " stop" , " producer" });
1039+ status = dinitctl_p.wait_for_term ({1 , 0 }); /* max 1 second */
1040+ igr_assert (status == 0 , " dinitctl did not exit cleanly" );
1041+
1042+ nanosleepx (0 , (1000000000u / 10u ) * 2u );
1043+
1044+ igr_assert_eq (read_file_contents (logged_output_file), " producer\n " " Producing output...\n " " Producing output...\n " );
1045+ }
0 commit comments