00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <time.h>
00027 #include <stdio.h>
00028 #include <errno.h>
00029 #include <string.h>
00030 #include <libxml/xmlwriter.h>
00031 #include <dlfcn.h>
00032 #include "testrunnerlite.h"
00033 #include "testdefinitiondatatypes.h"
00034 #include "executor.h"
00035 #include "hwinfo.h"
00036 #include "log.h"
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 LOCAL unsigned char *exec_command (const char *c);
00076
00077
00078
00079
00080
00081
00082
00087 LOCAL unsigned char *exec_command (const char *cmd)
00088 {
00089 char *p;
00090 exec_data edata;
00091 memset (&edata, 0x0, sizeof (exec_data));
00092 init_exec_data (&edata);
00093
00094 if (cmd == NULL || !strlen (cmd))
00095 return NULL;
00096
00097 edata.soft_timeout = DEFAULT_TIMEOUT;
00098 edata.hard_timeout = COMMON_HARD_TIMEOUT;
00099 LOG_MSG (LOG_INFO, "Getting HW information");
00100 execute (cmd, &edata);
00101
00102 if (edata.result) {
00103 LOG_MSG (LOG_ERR, "%s:%s():%d:%s\n", PROGNAME, __FUNCTION__,
00104 edata.result, (char *)edata.stderr_data.buffer ?
00105 (char *)edata.stderr_data.buffer :
00106 "no info available");
00107 free (edata.stderr_data.buffer);
00108 free (edata.stdout_data.buffer);
00109 return NULL;
00110 }
00111 p = strchr ((char *)edata.stdout_data.buffer, '\n');
00112 if (p) *p ='\0';
00113
00114 return edata.stdout_data.buffer;
00115 }
00116
00117
00118
00119
00124 int read_hwinfo (hw_info *hi)
00125 {
00126 void *plugin;
00127 const char *(*hwinfo_product) ();
00128 const char *(*hwinfo_hw_build) ();
00129 const char *(*hwinfo_extra) ();
00130
00131 memset (hi, 0x0, sizeof (hw_info));
00132
00133 plugin = dlopen ("/usr/lib/testrunner-lite-hwinfo.so",
00134 RTLD_NOW | RTLD_LOCAL);
00135 if (!plugin) {
00136 LOG_MSG (LOG_WARNING, "failed to load hwinfo plugin %s",
00137 dlerror());
00138 return 1;
00139 }
00140
00141 hwinfo_product = (const char*(*)())dlsym(plugin, "hwinfo_product");
00142 if (!hwinfo_product) {
00143 LOG_MSG (LOG_WARNING, "no function for hwinfo_product");
00144 } else {
00145 hi->product = exec_command (hwinfo_product());
00146 }
00147
00148 hwinfo_hw_build = (const char*(*)())dlsym(plugin, "hwinfo_hw_build");
00149 if (!hwinfo_hw_build) {
00150 LOG_MSG (LOG_WARNING, "no function for hwinfo_hw_build");
00151 } else {
00152 hi->hw_build = exec_command (hwinfo_hw_build());
00153 }
00154
00155 hwinfo_extra = (const char*(*)())dlsym(plugin, "hwinfo_extra");
00156 if (hwinfo_extra) {
00157 hi->extra = exec_command (hwinfo_extra());
00158 }
00159
00160 dlclose (plugin);
00161
00162 return 0;
00163 }
00164
00168 void print_hwinfo (hw_info *hi)
00169 {
00170 printf ("Hardware Info:\n");
00171 printf ("%s %s %s\n",
00172 (char *)(hi->product ? hi->product :
00173 (unsigned char *)"<none>"),
00174 (char *)(hi->hw_build ? hi->hw_build :
00175 (unsigned char *)"<none>"),
00176 (char *)(hi->extra ? hi->extra :
00177 (unsigned char *)""));
00178 }
00179
00183 void clean_hwinfo (hw_info *hi)
00184 {
00185
00186 if (hi->product) free (hi->product);
00187 if (hi->hw_build) free (hi->hw_build);
00188 if (hi->extra) free (hi->extra);
00189
00190 return;
00191 }
00192
00193
00194
00195
00196
00197