testing: Add testing mechanics.
Expose machine.h APIs and introduce code to make testing very easy.
This commit is contained in:
parent
6bd132a6b5
commit
8d1d9a7aaf
|
@ -4,10 +4,19 @@
|
||||||
* See LICENSE file for details.
|
* See LICENSE file for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define DEVELOPMENT 1
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "evisum_config.h"
|
#include "evisum_config.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
|
#if defined(DEVELOPMENT)
|
||||||
|
# include "system/machine.h"
|
||||||
|
# include "system/process.h"
|
||||||
|
# include "system/disks.h"
|
||||||
|
# include "system/filesystems.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_win_del_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
|
_win_del_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
|
||||||
void *event_info EINA_UNUSED)
|
void *event_info EINA_UNUSED)
|
||||||
|
@ -40,6 +49,47 @@ _win_add(void)
|
||||||
return ui;
|
return ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(DEVELOPMENT)
|
||||||
|
static void
|
||||||
|
_test(void)
|
||||||
|
{
|
||||||
|
Sys_Info *inf;
|
||||||
|
Eina_List *procs, *disks;
|
||||||
|
Proc_Info *proc;
|
||||||
|
File_System *fs;
|
||||||
|
char *path, *mount;
|
||||||
|
|
||||||
|
printf("Starting testing\n");
|
||||||
|
inf = system_info_all_get();
|
||||||
|
system_info_all_free(inf);
|
||||||
|
|
||||||
|
eina_init();
|
||||||
|
ecore_init();
|
||||||
|
|
||||||
|
procs = proc_info_all_get();
|
||||||
|
EINA_LIST_FREE(procs, proc)
|
||||||
|
proc_info_free(proc);
|
||||||
|
|
||||||
|
disks = disks_get();
|
||||||
|
EINA_LIST_FREE(disks, path)
|
||||||
|
{
|
||||||
|
mount = disk_mount_point_get(path);
|
||||||
|
if (mount)
|
||||||
|
{
|
||||||
|
fs = file_system_info_get(mount);
|
||||||
|
if (fs)
|
||||||
|
file_system_info_free(fs);
|
||||||
|
free(mount);
|
||||||
|
}
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
printf("Ending testing\n");
|
||||||
|
|
||||||
|
ecore_shutdown();
|
||||||
|
eina_shutdown();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -55,6 +105,13 @@ main(int argc, char **argv)
|
||||||
printf("Evisum version: %s\n", PACKAGE_VERSION);
|
printf("Evisum version: %s\n", PACKAGE_VERSION);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
#if defined(DEVELOPMENT)
|
||||||
|
else if (!strcmp(argv[i], "-t"))
|
||||||
|
{
|
||||||
|
_test();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
eina_init();
|
eina_init();
|
||||||
|
|
|
@ -369,8 +369,8 @@ _cpu_state_get(cpu_core_t **cores, int ncpu)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static cpu_core_t **
|
cpu_core_t **
|
||||||
_cpu_usage_get(int *ncpu)
|
system_cpu_usage_get(int *ncpu)
|
||||||
{
|
{
|
||||||
cpu_core_t **cores;
|
cpu_core_t **cores;
|
||||||
int i;
|
int i;
|
||||||
|
@ -405,8 +405,8 @@ _meminfo_parse_line(const char *line)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
void
|
||||||
_memory_usage_get(meminfo_t *memory)
|
system_memory_usage_get(meminfo_t *memory)
|
||||||
{
|
{
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
|
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
|
||||||
size_t len = 0, miblen;
|
size_t len = 0, miblen;
|
||||||
|
@ -628,10 +628,10 @@ swap_out:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
sensor_t **
|
||||||
_sensors_thermal_get(Sys_Info *info)
|
system_sensors_thermal_get(int *sensor_count)
|
||||||
{
|
{
|
||||||
sensor_t **sensors = info->sensors;
|
sensor_t **sensors = NULL;
|
||||||
#if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
sensor_t *sensor;
|
sensor_t *sensor;
|
||||||
int mibs[5] = { CTL_HW, HW_SENSORS, 0, 0, 0 };
|
int mibs[5] = { CTL_HW, HW_SENSORS, 0, 0, 0 };
|
||||||
|
@ -667,8 +667,8 @@ _sensors_thermal_get(Sys_Info *info)
|
||||||
if (snsr.type != SENSOR_TEMP)
|
if (snsr.type != SENSOR_TEMP)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sensors = realloc(sensors, 1 + info->sensor_count * sizeof(sensor_t *));
|
sensors = realloc(sensors, (1 + *sensor_count) * sizeof(sensor_t *));
|
||||||
sensors[info->sensor_count++] = sensor = calloc(1, sizeof(sensor_t));
|
sensors[(*sensor_count)++] = sensor = calloc(1, sizeof(sensor_t));
|
||||||
sensor->name = strdup(snsrdev.xname);
|
sensor->name = strdup(snsrdev.xname);
|
||||||
sensor->value = (snsr.value - 273150000) / 1000000.0; // (uK -> C)
|
sensor->value = (snsr.value - 273150000) / 1000000.0; // (uK -> C)
|
||||||
}
|
}
|
||||||
|
@ -679,8 +679,8 @@ _sensors_thermal_get(Sys_Info *info)
|
||||||
|
|
||||||
if ((sysctlbyname("hw.acpi.thermal.tz0.temperature", &value, &len, NULL, 0)) != -1)
|
if ((sysctlbyname("hw.acpi.thermal.tz0.temperature", &value, &len, NULL, 0)) != -1)
|
||||||
{
|
{
|
||||||
sensors = realloc(sensors, 1 + info->sensor_count * sizeof(sensor_t *));
|
sensors = realloc(sensors, (1 + *sensor_count) * sizeof(sensor_t *));
|
||||||
sensors[info->sensor_count++] = sensor = calloc(1, sizeof(sensor_t));
|
sensors[(*sensor_count)++] = sensor = calloc(1, sizeof(sensor_t));
|
||||||
sensor->name = strdup("hw.acpi.thermal.tz0");
|
sensor->name = strdup("hw.acpi.thermal.tz0");
|
||||||
sensor->value = (float) (value - 2732) / 10;
|
sensor->value = (float) (value - 2732) / 10;
|
||||||
}
|
}
|
||||||
|
@ -692,7 +692,7 @@ _sensors_thermal_get(Sys_Info *info)
|
||||||
int i, n;
|
int i, n;
|
||||||
|
|
||||||
n = scandir("/sys/class/thermal", &names, 0, alphasort);
|
n = scandir("/sys/class/thermal", &names, 0, alphasort);
|
||||||
if (n < 0) return;
|
if (n < 0) return NULL;
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
|
@ -708,8 +708,8 @@ _sensors_thermal_get(Sys_Info *info)
|
||||||
if (type)
|
if (type)
|
||||||
{
|
{
|
||||||
sensors =
|
sensors =
|
||||||
realloc(sensors, 1 + info->sensor_count * sizeof(sensor_t *));
|
realloc(sensors, (1 + (*sensor_count)) * sizeof(sensor_t *));
|
||||||
sensors[info->sensor_count++] =
|
sensors[(*sensor_count)++] =
|
||||||
sensor = calloc(1, sizeof(sensor_t));
|
sensor = calloc(1, sizeof(sensor_t));
|
||||||
|
|
||||||
sensor->name = strdup(names[i]->d_name);
|
sensor->name = strdup(names[i]->d_name);
|
||||||
|
@ -733,7 +733,7 @@ _sensors_thermal_get(Sys_Info *info)
|
||||||
free(names);
|
free(names);
|
||||||
#elif defined(__MacOS__)
|
#elif defined(__MacOS__)
|
||||||
#endif
|
#endif
|
||||||
info->sensors = sensors;
|
return sensors;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -1012,8 +1012,8 @@ _battery_state_get(power_t *power)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
_power_state_get(power_t *power)
|
system_power_state_get(power_t *power)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
#if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
|
@ -1167,8 +1167,8 @@ _linux_generic_network_status(unsigned long int *in,
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
void
|
||||||
_network_transfer_get(Sys_Info *info)
|
system_network_transfer_get(network_t *usage)
|
||||||
{
|
{
|
||||||
unsigned long first_in = 0, first_out = 0;
|
unsigned long first_in = 0, first_out = 0;
|
||||||
unsigned long last_in = 0, last_out = 0;
|
unsigned long last_in = 0, last_out = 0;
|
||||||
|
@ -1185,16 +1185,16 @@ _network_transfer_get(Sys_Info *info)
|
||||||
usleep(1000000);
|
usleep(1000000);
|
||||||
_freebsd_generic_network_status(&last_in, &last_out);
|
_freebsd_generic_network_status(&last_in, &last_out);
|
||||||
#endif
|
#endif
|
||||||
info->incoming = last_in - first_in;
|
usage->incoming = last_in - first_in;
|
||||||
info->outgoing = last_out - first_out;
|
usage->outgoing = last_out - first_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
_network_transfer_get_thread_cb(void *arg)
|
_network_transfer_get_thread_cb(void *arg)
|
||||||
{
|
{
|
||||||
Sys_Info *info = arg;
|
network_t *usage = arg;
|
||||||
|
|
||||||
_network_transfer_get(info);
|
system_network_transfer_get(usage);
|
||||||
|
|
||||||
return (void *)0;
|
return (void *)0;
|
||||||
}
|
}
|
||||||
|
@ -1214,7 +1214,8 @@ system_info_all_free(Sys_Info *info)
|
||||||
for (i = 0; i < info->sensor_count; i++)
|
for (i = 0; i < info->sensor_count; i++)
|
||||||
{
|
{
|
||||||
snsr = info->sensors[i];
|
snsr = info->sensors[i];
|
||||||
if (snsr->name) free(snsr->name);
|
if (snsr->name)
|
||||||
|
free(snsr->name);
|
||||||
free(snsr);
|
free(snsr);
|
||||||
}
|
}
|
||||||
if (info->sensors)
|
if (info->sensors)
|
||||||
|
@ -1247,16 +1248,16 @@ system_info_all_get(void)
|
||||||
info = calloc(1, sizeof(Sys_Info));
|
info = calloc(1, sizeof(Sys_Info));
|
||||||
if (!info) return NULL;
|
if (!info) return NULL;
|
||||||
|
|
||||||
info->cores = _cpu_usage_get(&info->cpu_count);
|
info->cores = system_cpu_usage_get(&info->cpu_count);
|
||||||
|
|
||||||
_memory_usage_get(&info->memory);
|
system_memory_usage_get(&info->memory);
|
||||||
|
|
||||||
error = pthread_create(&tid, NULL, _network_transfer_get_thread_cb, info);
|
error = pthread_create(&tid, NULL, _network_transfer_get_thread_cb, &info->network_usage);
|
||||||
if (error)
|
if (error)
|
||||||
_network_transfer_get(info);
|
system_network_transfer_get(&info->network_usage);
|
||||||
|
|
||||||
_power_state_get(&info->power);
|
system_power_state_get(&info->power);
|
||||||
_sensors_thermal_get(info);
|
info->sensors = system_sensors_thermal_get(&info->sensor_count);
|
||||||
|
|
||||||
if (!error)
|
if (!error)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,12 @@ typedef struct
|
||||||
int ac_mibs[5];
|
int ac_mibs[5];
|
||||||
} power_t;
|
} power_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned long incoming;
|
||||||
|
unsigned long outgoing;
|
||||||
|
} network_t;
|
||||||
|
|
||||||
typedef struct Sys_Info Sys_Info;
|
typedef struct Sys_Info Sys_Info;
|
||||||
struct Sys_Info
|
struct Sys_Info
|
||||||
{
|
{
|
||||||
|
@ -63,8 +69,7 @@ struct Sys_Info
|
||||||
int sensor_count;
|
int sensor_count;
|
||||||
sensor_t **sensors;
|
sensor_t **sensors;
|
||||||
|
|
||||||
unsigned long incoming;
|
network_t network_usage;
|
||||||
unsigned long outgoing;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Sys_Info *
|
Sys_Info *
|
||||||
|
@ -76,4 +81,16 @@ system_info_all_free(Sys_Info *);
|
||||||
int
|
int
|
||||||
system_cpu_online_count_get();
|
system_cpu_online_count_get();
|
||||||
|
|
||||||
|
cpu_core_t **
|
||||||
|
system_cpu_usage_get(int *ncpu);
|
||||||
|
|
||||||
|
void
|
||||||
|
system_memory_usage_get(meminfo_t *memory);
|
||||||
|
|
||||||
|
void
|
||||||
|
system_power_state_get(power_t *power);
|
||||||
|
|
||||||
|
void
|
||||||
|
system_network_transfer_get(network_t *usage);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -287,8 +287,8 @@ ui_tab_misc_update(Ui *ui, Sys_Info *info)
|
||||||
evas_object_size_hint_weight_set(box, EXPAND, EXPAND);
|
evas_object_size_hint_weight_set(box, EXPAND, EXPAND);
|
||||||
evas_object_show(box);
|
evas_object_show(box);
|
||||||
|
|
||||||
_network_usage_add(ui, box, info->incoming, EINA_TRUE);
|
_network_usage_add(ui, box, info->network_usage.incoming, EINA_TRUE);
|
||||||
_network_usage_add(ui, box, info->outgoing, EINA_FALSE);
|
_network_usage_add(ui, box, info->network_usage.outgoing, EINA_FALSE);
|
||||||
_separator_add(box);
|
_separator_add(box);
|
||||||
if (_battery_usage_add(box, &info->power))
|
if (_battery_usage_add(box, &info->power))
|
||||||
_separator_add(box);
|
_separator_add(box);
|
||||||
|
|
Loading…
Reference in New Issue