Skip to content

Commit 1716d9d

Browse files
committed
Update unit tests for fan speed auto-detection
Fixes #164. References #114.
1 parent b0cdfd4 commit 1716d9d

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

mbpfan.conf.test0

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[general]
2+
# see https://ineed.coffee/3838/a-beginners-tutorial-for-mbpfan-under-ubuntu for the values
3+
min_fan_speed = 2000 # put the *lowest* value of "cat /sys/devices/platform/applesmc.768/fan*_min"
4+
max_fan_speed = 6200 # put the *highest* value of "cat /sys/devices/platform/applesmc.768/fan*_max"
5+
low_temp = 63 # try ranges 55-63, default is 63
6+
high_temp = 66 # try ranges 58-66, default is 66
7+
max_temp = 86 # take highest number returned by "cat /sys/devices/platform/coretemp.*/hwmon/hwmon*/temp*_max", divide by 1000
8+
polling_interval = 7 # default is 7 seconds

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static int read_value(const char *path)
110110
}
111111

112112

113-
static void set_defaults(void)
113+
void set_defaults(void)
114114
{
115115
int i;
116116
char *path;

src/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
void check_requirements();
2+
void set_defaults();

src/minunit.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ static const char *test_config_file()
117117
return 0;
118118
}
119119

120-
mu_assert("Could not read min_fan_speed from config file",settings_get_int(settings, "general", "min_fan_speed") != 0);
121-
mu_assert("Could not read max_fan_speed from config file",settings_get_int(settings, "general", "max_fan_speed") != 0);
122120
mu_assert("Could not read low_temp from config file",settings_get_int(settings, "general", "low_temp") != 0);
123121
mu_assert("Could not read high_temp from config file",settings_get_int(settings, "general", "high_temp") != 0);
124122
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()
131129

132130
static const char *test_settings()
133131
{
132+
set_defaults();
134133
retrieve_settings("./mbpfan.conf.test1");
135134
mu_assert("max_fan_speed value is not 6200", max_fan_speed == 6200);
136135
mu_assert("polling_interval is not 1", polling_interval == 1);
137-
retrieve_settings("./mbpfan.conf");
136+
set_defaults();
137+
retrieve_settings("./mbpfan.conf.test0");
138138
mu_assert("min_fan_speed value is not 2000", min_fan_speed == 2000);
139139
mu_assert("polling_interval is not 7", polling_interval == 7);
140140
return 0;
@@ -170,11 +170,11 @@ static const char *test_settings_reload()
170170
signal(SIGHUP, handler);
171171
retrieve_settings("./mbpfan.conf");
172172
printf("Testing the _supplied_ mbpfan.conf (not the one you are using)..\n");
173-
mu_assert("min_fan_speed value is not 2000 before SIGHUP", min_fan_speed == 2000);
174-
mu_assert("polling_interval is not 7 before SIHUP", polling_interval == 7);
173+
// cannot tests min_fan_speed since it is not set and thus auto-detected
174+
mu_assert("polling_interval is not 7 before SIGHUP", polling_interval == 7);
175175
raise(SIGHUP);
176176
mu_assert("min_fan_speed value is not 6200 after SIGHUP", min_fan_speed == 6200);
177-
mu_assert("polling_interval is not 1 after SIHUP", polling_interval == 1);
177+
mu_assert("polling_interval is not 1 after SIGHUP", polling_interval == 1);
178178
retrieve_settings("./mbpfan.conf");
179179
return 0;
180180
}

0 commit comments

Comments
 (0)