commit - 4c166c1fa3977d61296ab892e25185412af3931a
commit + a06863098127b785c70045b5ed3693b663373aea
blob - 253b972a21bc6fd96ad7f2c9a5147cf0255afcad
blob + 5c8bfb668c5e50f74abe6e0848582c2192fb2db8
--- Makefile
+++ Makefile
static:
@cppcheck ${CPPCHECK_OPT}
-test:
- gcc tests.c -o tests -lcmocka
+test: tests.c helpers.c
+ gcc tests.c helpers.c -o tests -lcmocka
+ ./tests
.PHONY: fmt static
blob - 1e10dabcc02896ed343dcc7b687e408ccb68176f
blob + 335a33c3cbd0861e8241810c8ee083f61e6e8e36
--- helpers.c
+++ helpers.c
#include <sys/types.h>
#include <sys/utsname.h>
#include <time.h>
-
-#include "helpers.h"
-
-#include <catalog/pg_control.h>
-#include <common/controldata_utils.h>
-#include <miscadmin.h>
-#include <postgres.h>
#ifdef _WIN32
#include <windows.h>
#include <sys/sysinfo.h>
#include <unistd.h>
#endif
+
+#include "helpers.h"
#ifdef __linux__
#define num_elements(_a) (sizeof (_a) / sizeof (_a[0]))
#endif
return fs;
}
-
-char *system_db_id()
-{
- ControlFileData *ControlFile;
- bool crc_ok = 0;
- char *sysident_str;
- sysident_str = (char *)malloc(32);
-
- ControlFile = get_controlfile(DataDir, &crc_ok);
- if (!crc_ok)
- printf(_("WARNING: Calculated CRC checksum does not match value stored in file.\n"
- "Either the file is corrupt, or it has a different layout than this program\n"
- "is expecting. The results below are untrustworthy.\n\n"));
- snprintf(sysident_str, sizeof (sysident_str), UINT64_FORMAT, ControlFile->system_identifier);
- return sysident_str;
-}
blob - 61973f7b1b71305805461be8968315ad90bae945
blob + eb13a36141c44f4d9821f03b3cd7774f2a206357
--- helpers.h
+++ helpers.h
#ifndef HELPERS_H_INCLUDED
#define HELPERS_H_INCLUDED
+#include <stdint.h>
+#include <sys/types.h>
+#include <unistd.h>
+
#ifdef __linux__
#include <linux/magic.h>
#endif
osinfo* get_os_info( void );
hwinfo* get_hw_info( void );
-char* system_db_id( void );
char* dirfs( char* path );
-int get_proc_info( pid_t pid );
-int proc_uptime( int pid );
long long int get_proc_uptime( pid_t pid );
char* lookup_fstype( long fstype );
blob - 67a38b2467ea5e19c7699a3557a03161b07e0633
blob + 3fa503ee9f36e7dcc6c550b293e1dcb6c8786169
--- pg_feedback.c
+++ pg_feedback.c
*
* pg_feedback.c
*
- * Copyright (c) 2017, Sergey Bronnikov
+ * Copyright (c) 2017-2019, Sergey Bronnikov
*
*-------------------------------------------------------------------------
*/
-#include "common/controldata_utils.h"
-#include "fmgr.h"
-#include "funcapi.h"
-#include "miscadmin.h"
-#include "postgres.h"
-#include "postgres.h"
-#include "utils/builtins.h"
#include <inttypes.h>
#include <inttypes.h>
#include <stdlib.h>
+#include <stdio.h>
#include <unistd.h>
+#include <postgres.h>
+
+#include <miscadmin.h>
+#include <funcapi.h>
+#include <utils/builtins.h>
+#include <catalog/pg_control.h>
+#include <common/controldata_utils.h>
+
#include "helpers.h"
+static char *system_db_id()
+{
+ ControlFileData *ControlFile = NULL;
+ char *sysident_str = NULL;
+ sysident_str = (char *)malloc(32);
+ if (!sysident_str) {
+ perror("malloc");
+ return NULL;
+ }
+
+ ControlFile = get_controlfile(DataDir, NULL);
+ if (!ControlFile)
+ ereport(ERROR,
+ (errmsg("calculated CRC checksum does not match value stored in file")));
+ snprintf(sysident_str, sizeof (sysident_str), UINT64_FORMAT, ControlFile->system_identifier);
+
+ return sysident_str;
+}
+
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
blob - a586e4295edcbf9d2f2c5b117ccc1c8e8d02a4d1
blob + bce7bf78839e4efa3d1c9d76bdc53687eff4f117
--- tests.c
+++ tests.c
+#include <stdlib.h>
+#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
hw = malloc(sizeof(hwinfo));
assert_non_null(hw);
hw = get_hw_info();
- /* FIXME */
+ assert_int_not_equal(hw->ncpu, 0);
+ assert_int_not_equal(hw->memsize, 0);
+ assert_int_not_equal(hw->uptime, 0);
}
static void test_get_os_info(void **state)
osinfo *os = malloc(sizeof(osinfo));
assert_non_null(os);
os = get_os_info();
- /* FIXME */
+ assert_string_not_equal(os->os_version, "");
+ assert_string_not_equal(os->os_family, "");
+ assert_string_not_equal(os->os_name, "");
+ assert_string_not_equal(os->os_arch, "");
}
static void test_dirfs(void **state)
{
- char *p = NULL;
- p = dirfs("/");
- assert_non_null(p);
+ char *p = dirfs("/");
+ assert_string_not_equal(p, "");
}
+#ifdef __linux__
static void test_lookup_fstype(void **state)
{
- char *fs = NULL;
- char* lookup_fstype( long fstype );
- p = dirfs("/");
- assert_non_null(p);
+ char *type = lookup_fstype(1);
+ assert_string_equal(type, "<fs type unknown>");
}
+#endif
-static void test_proc_uptime(void **state)
-{
- int pid = 1;
- int t = 0;
- t = get_proc_uptime(pid);
- assert_int_not_equal(t, 0);
-}
-
static void test_get_proc_uptime(void **state)
{
pid_t pid = 1;
long long int t = 0;
- t = proc_uptime(pid);
+ t = get_proc_uptime(pid);
assert_int_not_equal(t, 0);
}
-static void test_get_proc_info(void **state)
-{
- pid_t pid = 1;
- int i = 0;
- i = get_proc_info(pid);
- assert_int_not_equal(i, 0);
-}
-
int main(void){
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_get_hw_info),
cmocka_unit_test(test_get_os_info),
+ cmocka_unit_test(test_get_proc_uptime),
cmocka_unit_test(test_dirfs),
+#ifdef __linux__
cmocka_unit_test(test_lookup_fstype),
- cmocka_unit_test(test_get_proc_uptime),
- cmocka_unit_test(test_get_proc_info),
- cmocka_unit_test(test_proc_uptime)
+#endif
};
return cmocka_run_group_tests(tests, NULL, NULL);