2 * Name : time_set_effective_id
3 * Author : Chris Koeritz
6 * A simple test of how long it takes to call set effective id on Unix.
7 * For this to really work as designed, it should be run as root.
9 * Copyright (c) 2003-$now By Author. This program is free software; you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation; either version 2 of
12 * the License or (at your option) any later version. This is online at:
13 * http://www.fsf.org/copyleft/gpl.html
14 * Please send any updates to: fred@gruntose.com
17 #include <basis/functions.h>
18 #include <basis/astring.h>
19 #include <structures/set.h>
20 #include <timely/time_stamp.h>
21 #include <application/hoople_main.h>
22 #include <loggers/console_logger.h>
23 #include <loggers/file_logger.h>
24 #include <structures/static_memory_gremlin.h>
26 using namespace application;
27 using namespace basis;
28 using namespace loggers;
29 using namespace filesystem;
30 using namespace textual;
31 using namespace timely;
34 #define BASE_LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
36 #define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
38 class time_set_effective_id : public application_shell
41 time_set_effective_id() : application_shell() {}
42 DEFINE_CLASS_NAME("time_set_effective_id");
46 int time_set_effective_id::execute()
52 int test_runs = 1000000;
54 time_stamp start; // start of test.
55 for (int i = 0; i < test_runs; i++) {
56 // set effective id to fred.
57 int ret = seteuid(1008);
59 LOG("failure to change effective user id to normal user.");
62 // set effective id to root.
65 LOG("failure to change effective user id to root.");
69 time_stamp completion_time; // end of test.
71 double durat = completion_time.value() - start.value();
72 double secs = durat / 1000.0; // convert to seconds.
73 LOG(a_sprintf("test run took %0.2f milliseconds or %0.2f seconds or %0.2f minutes.", durat, secs, secs / 60.0));
74 // divide by two because we're doing two calls above.
75 LOG(a_sprintf("individual call takes %0.0f milliseconds.", durat / double(test_runs) / 2.0));
81 HOOPLE_MAIN(time_set_effective_id, )
83 #ifdef __BUILD_STATIC_APPLICATION__
84 // static dependencies found by buildor_gen_deps.sh:
85 #endif // __BUILD_STATIC_APPLICATION__