FOSSology  4.7.1
Open Source License Compliance by Open Source Software
testRun.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2011, 2012 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <assert.h>
15 #include <pwd.h>
16 #include <grp.h>
17 #include <CUnit/CUnit.h>
18 #include <CUnit/Automated.h>
19 #include <gio/gio.h>
20 #include <glib.h>
21 
22 #include <libfossology.h>
23 #include <libfocunit.h>
24 #include <libfodbreposysconf.h>
25 #include <testRun.h>
26 
27 #include <agent.h>
28 #include <database.h>
29 #include <event.h>
30 #include <host.h>
31 #include <interface.h>
32 #include <logging.h>
33 #include <scheduler.h>
34 
35 /* ************************************************************************** */
36 /* **** suite initializations *********************************************** */
37 /* ************************************************************************** */
38 
39 char* testdb = NULL;
40 
47 int init_suite(void)
48 {
49  if(main_log)
51  main_log = log_new("./founit.log", "UNIT_TESTS", getpid());
52  return 0;
53 }
54 
62 int clean_suite(void)
63 {
64  if(main_log)
66 
67  main_log = NULL;
68  return 0;
69 }
70 
71 /* ************************************************************************** */
72 /* *** main and suite decl ************************************************** */
73 /* ************************************************************************** */
74 
75 /* create test suite */
77 CU_SuiteInfo suites[] =
78 {
79  {"Host", NULL, NULL, (CU_SetUpFunc)init_suite, (CU_TearDownFunc)clean_suite, tests_host },
80  {"Interface", NULL, NULL, (CU_SetUpFunc)init_suite, (CU_TearDownFunc)clean_suite, tests_interface },
81  {"InterfaceThread", NULL, NULL, (CU_SetUpFunc)init_suite, (CU_TearDownFunc)clean_suite, tests_interface_thread },
82  {"Database", NULL, NULL, (CU_SetUpFunc)init_suite, (CU_TearDownFunc)clean_suite, tests_database },
83  {"Email", NULL, NULL, (CU_SetUpFunc)init_suite, (CU_TearDownFunc)clean_suite, tests_email },
84  {"Job", NULL, NULL, (CU_SetUpFunc)init_suite, (CU_TearDownFunc)clean_suite, tests_job },
85  {"Scheduler", NULL, NULL, (CU_SetUpFunc)init_suite, (CU_TearDownFunc)clean_suite, tests_scheduler },
86  {"MetaAgent", NULL, NULL, (CU_SetUpFunc)init_suite, (CU_TearDownFunc)clean_suite, tests_meta_agent },
87  {"Agent", NULL, NULL, (CU_SetUpFunc)init_suite, (CU_TearDownFunc)clean_suite, tests_agent },
88  {"Event", NULL, NULL, (CU_SetUpFunc)init_suite, (CU_TearDownFunc)clean_suite, tests_event },
89  CU_SUITE_INFO_NULL
90 };
91 
92 int main( int argc, char *argv[] )
93 {
94 #if !GLIB_CHECK_VERSION(2,35,0)
95  g_type_init ();
96  g_thread_init(NULL);
97 #endif
98 
99  fo_dbManager* dbManager = createTestEnvironment(AGENT_DIR, NULL, 1);
100  testdb = get_sysconfdir();
101 
102  /* createTestEnvironment writes a minimal fossology.conf that lacks the
103  * [FOSSOLOGY].port key and [SCHEDULER] section required by scheduler_foss_config.
104  * Overwrite it with a complete one using the current user/group credentials. */
105  {
106  struct passwd* pw = getpwuid(getuid());
107  struct group* gr = getgrgid(getgid());
108  gchar* confpath = g_strdup_printf("%s/fossology.conf", testdb);
109  FILE* f = fopen(confpath, "w");
110  if(f)
111  {
112  fprintf(f,
113  "[FOSSOLOGY]\nport = 12354\naddress = localhost\ndepth = 0\npath = %s/repo\n"
114  "[REPOSITORY]\nlocalhost[] = * 00 ff\n"
115  "[SCHEDULER]\nagent_death_timer = 10\nagent_update_interval = 15\nagent_update_number = 1\n"
116  "[DIRECTORIES]\nMODDIR = %s\nLOGDIR = %s\nPROJECTGROUP = %s\nPROJECTUSER = %s\n",
117  testdb, testdb, testdb,
118  gr ? gr->gr_name : PROJECT_GROUP,
119  pw ? pw->pw_name : PROJECT_USER);
120  fclose(f);
121  }
122  g_free(confpath);
123  }
124 
125  int result = focunit_main(argc, argv, "scheduler_Tests", suites);
126 
127  dropTestEnvironment(dbManager, AGENT_DIR, NULL);
128  return result;
129 }
Header file with agent related operations.
int main(int argc, char *argv[])
main test function
Definition: testRun.c:134
CU_SuiteInfo suites[]
all test suites for delagent
Definition: testRun.h:36
Event handling operations.
char * get_sysconfdir()
get sysconfig dir path just created by create_db_repo_sysconf()
The main FOSSology C library.
log_t * main_log
Definition: logging.c:33
log_t * log_new(gchar *log_name, gchar *pro_name, pid_t pro_pid)
Creates a new log.
Definition: logging.c:81
void log_destroy(log_t *log)
Free memory associated with the log file.
Definition: logging.c:150
Log related operations.
fo_dbManager * dbManager
fo_dbManager object
Definition: testRun.c:22
int init_suite(void)
Definition: testRun.c:47
int clean_suite(void)
Definition: testRun.c:62