mbpfan-josie

Update unit tests for fan speed auto-detection

Fixes #164.  References #114.

1716d9d877a08e0bce0b9a5cf7222ff3a4829e66
Andrew Gaul <andrew@gaul.org> · 2018-09-13T10:29 · browse files at this commit

parents: b0cdfd4

diff --git a/mbpfan.conf.test0 b/mbpfan.conf.test0
new file mode 100644
index 0000000..1c1c01d
--- /dev/null
+++ b/mbpfan.conf.test0
@@ -0,0 +1,8 @@
+[general]
+# see https://ineed.coffee/3838/a-beginners-tutorial-for-mbpfan-under-ubuntu for the values
+min_fan_speed = 2000	# put the *lowest* value of "cat /sys/devices/platform/applesmc.768/fan*_min"
+max_fan_speed = 6200	# put the *highest* value of "cat /sys/devices/platform/applesmc.768/fan*_max"
+low_temp = 63			# try ranges 55-63, default is 63
+high_temp = 66			# try ranges 58-66, default is 66
+max_temp = 86			# take highest number returned by "cat /sys/devices/platform/coretemp.*/hwmon/hwmon*/temp*_max", divide by 1000
+polling_interval = 7	# default is 7 seconds
diff --git a/src/main.c b/src/main.c
index 4413e89..75db7b9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -110,7 +110,7 @@ static int read_value(const char *path)
 }
 
 
-static void set_defaults(void)
+void set_defaults(void)
 {
     int i;
     char *path;
diff --git a/src/main.h b/src/main.h
index 13013e8..31474f2 100644
--- a/src/main.h
+++ b/src/main.h
@@ -1 +1,2 @@
 void check_requirements();
+void set_defaults();
diff --git a/src/minunit.c b/src/minunit.c
index 8e88eea..fc19871 100644
--- a/src/minunit.c
+++ b/src/minunit.c
@@ -117,8 +117,6 @@ static const char *test_config_file()
         return 0;
     }
 
-    mu_assert("Could not read min_fan_speed from config file",settings_get_int(settings, "general", "min_fan_speed") != 0);
-    mu_assert("Could not read max_fan_speed from config file",settings_get_int(settings, "general", "max_fan_speed") != 0);
     mu_assert("Could not read low_temp from config file",settings_get_int(settings, "general", "low_temp") != 0);
     mu_assert("Could not read high_temp from config file",settings_get_int(settings, "general", "high_temp") != 0);
     mu_assert("Could not read max_temp from config file",settings_get_int(settings, "general", "max_temp") != 0);
@@ -131,10 +129,12 @@ static const char *test_config_file()
 
 static const char *test_settings()
 {
+    set_defaults();
     retrieve_settings("./mbpfan.conf.test1");
     mu_assert("max_fan_speed value is not 6200", max_fan_speed == 6200);
     mu_assert("polling_interval is not 1", polling_interval == 1);
-    retrieve_settings("./mbpfan.conf");
+    set_defaults();
+    retrieve_settings("./mbpfan.conf.test0");
     mu_assert("min_fan_speed value is not 2000", min_fan_speed == 2000);
     mu_assert("polling_interval is not 7", polling_interval == 7);
     return 0;
@@ -170,11 +170,11 @@ static const char *test_settings_reload()
     signal(SIGHUP, handler);
     retrieve_settings("./mbpfan.conf");
     printf("Testing the _supplied_ mbpfan.conf (not the one you are using)..\n");
-    mu_assert("min_fan_speed value is not 2000 before SIGHUP", min_fan_speed == 2000);
-    mu_assert("polling_interval is not 7 before SIHUP", polling_interval == 7);
+    // cannot tests min_fan_speed since it is not set and thus auto-detected
+    mu_assert("polling_interval is not 7 before SIGHUP", polling_interval == 7);
     raise(SIGHUP);
     mu_assert("min_fan_speed value is not 6200 after SIGHUP", min_fan_speed == 6200);
-    mu_assert("polling_interval is not 1 after SIHUP", polling_interval == 1);
+    mu_assert("polling_interval is not 1 after SIGHUP", polling_interval == 1);
     retrieve_settings("./mbpfan.conf");
     return 0;
 }