~xnox/upstart/no-multibuild

« back to all changes in this revision

Viewing changes to util/tests/test_initctl.c

  • Committer: Dmitrijs Ledkovs
  • Date: 2013-11-12 14:00:36 UTC
  • mfrom: (1567.1.2 upstart)
  • Revision ID: dmitrijs.ledkovs@canonical.com-20131112140036-qykpb008b91vqi3x
MergeĀ lp:~jamesodhunt/upstart/cleanup-test-xdg-dirs

Show diffs side-by-side

added added

removed removed

Lines of Context:
10988
10988
        TEST_EQ (unsetenv ("UPSTART_CONFDIR"), 0);
10989
10989
        TEST_EQ (unsetenv ("UPSTART_LOGDIR"), 0);
10990
10990
 
10991
 
 
10992
 
        if (! getenv ("XDG_RUNTIME_DIR")) {
10993
 
                TEST_GROUP ("set-env rexec # TODO fails without XDG_RUNTIME_DIR set");
10994
 
                TEST_FAILED ();
10995
 
                return;
10996
 
        } else {
10997
 
 
10998
10991
        /*******************************************************************/
10999
10992
        TEST_FEATURE ("ensure 'set-env' persists across session-init re-exec");
11000
10993
 
 
10994
        TEST_TRUE (getenv ("XDG_RUNTIME_DIR"));
 
10995
 
11001
10996
        contents = nih_sprintf (NULL, 
11002
10997
                        "start on startup\n"
11003
10998
                        "\n"
11056
11051
        assert0 (unlink (logfile));
11057
11052
        DELETE_FILE (confdir, "foo.conf");
11058
11053
 
11059
 
        }
11060
 
 
11061
11054
        /*******************************************************************/
11062
11055
        TEST_FEATURE ("ensure 'set-env --global' persists across session-init re-exec");
11063
11056
 
11114
11107
        nih_local char  *session_file = NULL;
11115
11108
        nih_local char  *path = NULL;
11116
11109
        nih_local char  *expected = NULL;
11117
 
        nih_local char  *orig_xdg_runtime_dir = NULL;
11118
11110
        size_t           len;
11119
11111
        char            *value;
11120
11112
 
11126
11118
        TEST_FILENAME (confdir);
11127
11119
        TEST_EQ (mkdir (confdir, 0755), 0);
11128
11120
 
11129
 
        /* Take care to avoid disrupting users environment by saving and
11130
 
         * restoring this variable (assuming the tests all pass...).
11131
 
         */
11132
 
        orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
11133
 
        if (orig_xdg_runtime_dir)
11134
 
                orig_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, orig_xdg_runtime_dir));
11135
 
 
11136
11121
        /*******************************************************************/
11137
11122
        TEST_FEATURE ("with no instances and XDG_RUNTIME_DIR unset");
11138
11123
 
11210
11195
 
11211
11196
        /*******************************************************************/
11212
11197
 
11213
 
        if (orig_xdg_runtime_dir) {
11214
 
                /* restore */
11215
 
                setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1);
11216
 
        } else {
11217
 
                assert0 (unsetenv ("XDG_RUNTIME_DIR"));
11218
 
        }
11219
 
 
11220
11198
        assert0 (unsetenv ("UPSTART_CONFDIR"));
11221
11199
 
11222
11200
        TEST_EQ (rmdir (dirname), 0);
11302
11280
        char                    **output;
11303
11281
        size_t                    lines;
11304
11282
        nih_local NihDBusProxy   *upstart = NULL;
11305
 
        nih_local char           *orig_xdg_runtime_dir = NULL;
11306
11283
        nih_local char           *session_file = NULL;
11307
11284
        nih_local char           *job = NULL;
11308
11285
        pid_t                     job_pid;
11318
11295
        TEST_FILENAME (sessiondir);
11319
11296
        TEST_EQ (mkdir (sessiondir, 0755), 0);
11320
11297
 
11321
 
        /* Take care to avoid disrupting users environment by saving and
11322
 
         * restoring this variable (assuming the tests all pass...).
11323
 
         */
11324
 
        orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
11325
 
        if (orig_xdg_runtime_dir)
11326
 
                orig_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, orig_xdg_runtime_dir));
11327
 
 
11328
11298
        /* Use the "secret" interface */
11329
11299
        TEST_EQ (setenv ("UPSTART_CONFDIR", confdir, 1), 0);
11330
11300
        TEST_EQ (setenv ("UPSTART_LOGDIR", logdir, 1), 0);
12054
12024
        assert0 (unsetenv ("UPSTART_CONFDIR"));
12055
12025
        assert0 (unsetenv ("UPSTART_LOGDIR"));
12056
12026
 
12057
 
        if (orig_xdg_runtime_dir) {
12058
 
                /* restore */
12059
 
                setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1);
12060
 
        } else {
12061
 
                assert0 (unsetenv ("XDG_RUNTIME_DIR"));
12062
 
        }
12063
 
 
12064
12027
        TEST_EQ (rmdir (logdir), 0);
12065
12028
        TEST_EQ (rmdir (confdir), 0);
12066
12029
 
12078
12041
{
12079
12042
        char             confdir[PATH_MAX];
12080
12043
        char             dirname[PATH_MAX];
12081
 
        nih_local char  *orig_xdg_runtime_dir = NULL;
12082
12044
        char             logdir[PATH_MAX];
12083
12045
        pid_t            upstart_pid = 0;
12084
12046
        nih_local char  *logfile = NULL;
12090
12052
        mode_t           test_umask = 0077;
12091
12053
        mode_t           default_umask = 022;
12092
12054
 
12093
 
 
12094
 
        /* Take care to avoid disrupting users environment by saving and
12095
 
         * restoring this variable (assuming the tests all pass...).
12096
 
         */
12097
 
        orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
12098
 
        if (orig_xdg_runtime_dir)
12099
 
                orig_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, orig_xdg_runtime_dir));
12100
 
 
12101
12055
        TEST_FILENAME (dirname);
12102
12056
        TEST_EQ (mkdir (dirname, 0755), 0);
12103
12057
        TEST_EQ (setenv ("XDG_RUNTIME_DIR", dirname, 1), 0);
12176
12130
        /* Restore */
12177
12131
        (void)umask (original_umask);
12178
12132
 
12179
 
        if (orig_xdg_runtime_dir) {
12180
 
                /* restore */
12181
 
                setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1);
12182
 
        } else {
12183
 
                assert0 (unsetenv ("XDG_RUNTIME_DIR"));
12184
 
        }
12185
 
 
12186
12133
        assert0 (rmdir (confdir));
12187
12134
        assert0 (rmdir (logdir));
12188
12135
}
15794
15741
        char            *args[2];
15795
15742
        int              ret = 0;                         
15796
15743
 
15797
 
        if (! getenv ("XDG_RUNTIME_DIR")) {
15798
 
                TEST_GROUP ("usage # TODO fails without XDG_RUNTIME_DIR set");
15799
 
                TEST_FAILED ();
15800
 
                return;
15801
 
        }
 
15744
        TEST_TRUE (getenv ("XDG_RUNTIME_DIR"));
15802
15745
 
15803
15746
        TEST_GROUP ("usage");
15804
15747
 
16870
16813
{
16871
16814
        char             confdir[PATH_MAX];
16872
16815
        char             logdir[PATH_MAX];
16873
 
        char             runtimedir[PATH_MAX];
16874
16816
        size_t           lines;
16875
16817
        pid_t            dbus_pid = 0;
16876
16818
        pid_t            upstart_pid = 0;
16877
16819
        char            *value;
16878
 
        nih_local char  *orig_xdg_runtime_dir = NULL;
16879
16820
        nih_local char  *cmd = NULL;
16880
16821
        char           **output;
16881
16822
        nih_local char  *session_file = NULL;
 
16823
        char            *xdg_runtime_dir;
 
16824
 
 
16825
        xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
 
16826
        TEST_TRUE (xdg_runtime_dir);
16882
16827
 
16883
16828
        TEST_GROUP ("job process table commands");
16884
16829
 
16888
16833
        TEST_FILENAME (logdir);
16889
16834
        TEST_EQ (mkdir (logdir, 0755), 0);
16890
16835
 
16891
 
        TEST_FILENAME (runtimedir);
16892
 
        TEST_EQ (mkdir (runtimedir, 0755), 0);
16893
 
 
16894
16836
        /* Use the "secret" interface */
16895
16837
        TEST_EQ (setenv ("UPSTART_CONFDIR", confdir, 1), 0);
16896
16838
        TEST_EQ (setenv ("UPSTART_LOGDIR", logdir, 1), 0);
16897
16839
 
16898
 
        /* Take care to avoid disrupting users environment by saving and
16899
 
         * restoring this variable (assuming the tests all pass...).
16900
 
         */
16901
 
        orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
16902
 
        if (orig_xdg_runtime_dir)
16903
 
                orig_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, orig_xdg_runtime_dir));
16904
 
 
16905
 
        TEST_EQ (setenv ("XDG_RUNTIME_DIR", runtimedir, 1), 0);
16906
 
 
16907
16840
        /*******************************************************************/
16908
16841
        /* Ensure basic variables are set in the current environment */
16909
16842
 
16954
16887
 
16955
16888
        STOP_UPSTART (upstart_pid);
16956
16889
        session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",
16957
 
                                runtimedir, (int)upstart_pid));
 
16890
                                xdg_runtime_dir, (int)upstart_pid));
16958
16891
        unlink (session_file);
16959
16892
 
16960
16893
        /*******************************************************************/
16961
16894
 
16962
 
        test_no_inherit_job_env (runtimedir, confdir, logdir);
 
16895
        test_no_inherit_job_env (xdg_runtime_dir, confdir, logdir);
16963
16896
 
16964
16897
        /*******************************************************************/
16965
16898
 
16968
16901
        assert0 (unsetenv ("UPSTART_LOGDIR"));
16969
16902
        assert0 (unsetenv ("UPSTART_SESSION"));
16970
16903
 
16971
 
        session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions", runtimedir));
16972
 
        TEST_EQ (rmdir (session_file), 0);
16973
 
        session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart", runtimedir));
16974
 
        TEST_EQ (rmdir (session_file), 0);
16975
 
        TEST_EQ (rmdir (runtimedir), 0);
16976
 
 
16977
 
        if (orig_xdg_runtime_dir) {
16978
 
                /* restore */
16979
 
                setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1);
16980
 
        } else {
16981
 
                assert0 (unsetenv ("XDG_RUNTIME_DIR"));
16982
 
        }
16983
 
 
16984
16904
        TEST_EQ (rmdir (confdir), 0);
16985
16905
        TEST_EQ (rmdir (logdir), 0);
16986
16906
}
16994
16914
        pid_t            upstart_pid = 0;
16995
16915
        nih_local char  *cmd = NULL;
16996
16916
        char           **output;
16997
 
        nih_local char  *orig_xdg_runtime_dir = NULL;
16998
16917
        nih_local char  *dbus_session_address = NULL;
16999
16918
        nih_local char  *dbus_session_address2 = NULL;
17000
16919
        nih_local char  *upstart_session = NULL;
17001
16920
        char            *address;
17002
 
        char             dirname[PATH_MAX];
17003
16921
 
17004
 
        /* Take care to avoid disrupting users environment by saving and
17005
 
         * restoring this variable (assuming the tests all pass...).
17006
 
         */
17007
 
        orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
17008
 
        if (orig_xdg_runtime_dir)
17009
 
                orig_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, orig_xdg_runtime_dir));
17010
 
        TEST_FILENAME (dirname);
17011
 
        TEST_EQ (mkdir (dirname, 0755), 0);
17012
 
        TEST_EQ (setenv ("XDG_RUNTIME_DIR", dirname, 1), 0);
 
16922
        TEST_TRUE (getenv ("XDG_RUNTIME_DIR"));
17013
16923
 
17014
16924
        TEST_GROUP ("D-Bus connection");
17015
16925
 
17204
17114
 
17205
17115
        /* Stop the 2nd daemon */
17206
17116
        TEST_DBUS_END (dbus_pid2);
17207
 
 
17208
 
        /* Restore */
17209
 
        if (orig_xdg_runtime_dir) {
17210
 
                /* restore */
17211
 
                setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1);
17212
 
        } else {
17213
 
                assert0 (unsetenv ("XDG_RUNTIME_DIR"));
17214
 
        }
17215
17117
}
17216
17118
 
17217
17119
int
17225
17127
        nih_main_loop_init ();
17226
17128
        program_name = "test";
17227
17129
 
 
17130
        test_common_setup ();
 
17131
 
17228
17132
        test_upstart_open ();
17229
17133
        test_job_status ();
17230
17134
 
17269
17173
 
17270
17174
        test_dbus_connection ();
17271
17175
 
 
17176
        test_common_cleanup ();
 
17177
 
17272
17178
        return 0;
17273
17179
}