Skip to content

Commit c562105

Browse files
committed
ctests: stop including C files in the test files
With these changes, a copy of libnetplan without static functions will be build. All the test files will be linked against this separate library. With that, there is no need to include the C files in the test files anymore. To make this possible, all the static keywords in function declarations were replaced with a macro that will be defined at compilation time.
1 parent 6f4fbc0 commit c562105

24 files changed

+294
-333
lines changed

src/error.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* Loading and error handling
3232
****************************************************/
3333

34-
static void
34+
STATIC void
3535
write_error_marker(GString *message, int column)
3636
{
3737
int i;
@@ -42,7 +42,7 @@ write_error_marker(GString *message, int column)
4242
g_string_append_printf(message, "^");
4343
}
4444

45-
static char *
45+
STATIC char *
4646
get_syntax_error_context(const NetplanParser* npp, const int line_num, const int column, GError **error)
4747
{
4848
GString *message = NULL;
@@ -72,7 +72,7 @@ get_syntax_error_context(const NetplanParser* npp, const int line_num, const int
7272
return g_string_free(message, FALSE);
7373
}
7474

75-
static char *
75+
STATIC char *
7676
get_parser_error_context(const yaml_parser_t *parser, __unused GError **error)
7777
{
7878
GString *message = NULL;

src/meson.build

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ libnetplan = library(
2525
soversion: '0.0',
2626
install: true)
2727

28+
libnetplan_testing = library(
29+
'netplan_testing',
30+
sources,
31+
gnu_symbol_visibility: 'default',
32+
c_args: ['-DUNITTESTS'],
33+
link_args: ['-T', linker_script],
34+
link_depends: linker_script,
35+
dependencies: [glib, gio, yaml, uuid],
36+
include_directories: inc,
37+
soversion: '0.0',
38+
install: false)
39+
2840
libexec_netplan = join_paths(get_option('libexecdir'), 'netplan')
2941
executable(
3042
'generate',

src/netplan.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ gchar *tmp = NULL;
9999

100100
#define DIRTY_COMPLEX(_def, _data) complex_object_is_dirty(_def, (char*)(&_data), sizeof(_data))
101101

102-
static gboolean
102+
STATIC gboolean
103103
write_match(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
104104
{
105105
YAML_SCALAR_PLAIN(event, emitter, "match");
@@ -121,7 +121,7 @@ write_match(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefini
121121
err_path: return FALSE; // LCOV_EXCL_LINE
122122
}
123123

124-
static gboolean
124+
STATIC gboolean
125125
write_auth(yaml_event_t* event, yaml_emitter_t* emitter, NetplanAuthenticationSettings auth)
126126
{
127127
YAML_SCALAR_PLAIN(event, emitter, "auth");
@@ -145,7 +145,7 @@ write_auth(yaml_event_t* event, yaml_emitter_t* emitter, NetplanAuthenticationSe
145145
err_path: return FALSE; // LCOV_EXCL_LINE
146146
}
147147

148-
static gboolean
148+
STATIC gboolean
149149
write_bond_params(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
150150
{
151151
if (DIRTY(def, def->bond_params)
@@ -205,7 +205,7 @@ write_bond_params(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNet
205205
err_path: return FALSE; // LCOV_EXCL_LINE
206206
}
207207

208-
static gboolean
208+
STATIC gboolean
209209
write_vxlan(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
210210
{
211211
if (def->type == NETPLAN_DEF_TYPE_TUNNEL && def->tunnel.mode == NETPLAN_TUNNEL_MODE_VXLAN) {
@@ -267,7 +267,7 @@ write_vxlan(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefini
267267
err_path: return FALSE; // LCOV_EXCL_LINE
268268
}
269269

270-
static gboolean
270+
STATIC gboolean
271271
write_bridge_params(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def, const GArray *interfaces)
272272
{
273273
if (def->custom_bridging || DIRTY_COMPLEX(def, def->bridge_params)) {
@@ -316,7 +316,7 @@ write_bridge_params(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanN
316316
err_path: return FALSE; // LCOV_EXCL_LINE
317317
}
318318

319-
static gboolean
319+
STATIC gboolean
320320
write_modem_params(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
321321
{
322322
/* some modem settings to auto-detect GSM vs CDMA connections */
@@ -339,7 +339,7 @@ typedef struct {
339339
yaml_emitter_t* emitter;
340340
} _passthrough_handler_data;
341341

342-
static void
342+
STATIC void
343343
_passthrough_handler(GQuark key_id, gpointer value, gpointer user_data)
344344
{
345345
_passthrough_handler_data *d = user_data;
@@ -348,7 +348,7 @@ _passthrough_handler(GQuark key_id, gpointer value, gpointer user_data)
348348
err_path: return; // LCOV_EXCL_LINE
349349
}
350350

351-
static gboolean
351+
STATIC gboolean
352352
write_backend_settings(yaml_event_t* event, yaml_emitter_t* emitter, NetplanBackendSettings s) {
353353
if (s.uuid || s.name || s.passthrough) {
354354
YAML_SCALAR_PLAIN(event, emitter, "networkmanager");
@@ -371,7 +371,7 @@ write_backend_settings(yaml_event_t* event, yaml_emitter_t* emitter, NetplanBack
371371
err_path: return FALSE; // LCOV_EXCL_LINE
372372
}
373373

374-
static gboolean
374+
STATIC gboolean
375375
write_access_points(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
376376
{
377377
NetplanWifiAccessPoint* ap = NULL;
@@ -407,7 +407,7 @@ write_access_points(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanN
407407
err_path: return FALSE; // LCOV_EXCL_LINE
408408
}
409409

410-
static gboolean
410+
STATIC gboolean
411411
write_addresses(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
412412
{
413413
YAML_SCALAR_PLAIN(event, emitter, "addresses");
@@ -438,7 +438,7 @@ write_addresses(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDe
438438
err_path: return FALSE; // LCOV_EXCL_LINE
439439
}
440440

441-
static gboolean
441+
STATIC gboolean
442442
write_nameservers(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
443443
{
444444
YAML_SCALAR_PLAIN(event, emitter, "nameservers");
@@ -470,7 +470,7 @@ write_nameservers(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNet
470470
err_path: return FALSE; // LCOV_EXCL_LINE
471471
}
472472

473-
static gboolean
473+
STATIC gboolean
474474
write_dhcp_overrides(yaml_event_t* event, yaml_emitter_t* emitter, const char* key, const NetplanNetDefinition* def, const NetplanDHCPOverrides* data)
475475
{
476476
if (DIRTY_COMPLEX(def, *data)
@@ -500,7 +500,7 @@ write_dhcp_overrides(yaml_event_t* event, yaml_emitter_t* emitter, const char* k
500500
err_path: return FALSE; // LCOV_EXCL_LINE
501501
}
502502

503-
static gboolean
503+
STATIC gboolean
504504
write_tunnel_settings(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
505505
{
506506
YAML_NONNULL_STRING(event, emitter, "mode", netplan_tunnel_mode_name(def->tunnel.mode));
@@ -573,7 +573,7 @@ write_tunnel_settings(yaml_event_t* event, yaml_emitter_t* emitter, const Netpla
573573
err_path: return FALSE; // LCOV_EXCL_LINE
574574
}
575575

576-
static gboolean
576+
STATIC gboolean
577577
write_routes(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
578578
{
579579
if (def->routes && def->routes->len > 0) {
@@ -625,7 +625,7 @@ write_routes(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefin
625625
err_path: return FALSE; // LCOV_EXCL_LINE
626626
}
627627

628-
static gboolean
628+
STATIC gboolean
629629
write_openvswitch(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanOVSSettings* ovs, NetplanBackend backend, GHashTable *ovs_ports)
630630
{
631631
GHashTableIter iter;
@@ -714,7 +714,7 @@ write_openvswitch(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanOVS
714714
err_path: return FALSE; // LCOV_EXCL_LINE
715715
}
716716

717-
static void
717+
STATIC void
718718
_serialize_yaml(
719719
const NetplanState* np_state,
720720
yaml_event_t* event,
@@ -1007,15 +1007,15 @@ netplan_netdef_write_yaml(
10071007
// LCOV_EXCL_STOP
10081008
}
10091009

1010-
static int
1010+
STATIC int
10111011
contains_netdef_type(gconstpointer value, gconstpointer user_data)
10121012
{
10131013
const NetplanNetDefinition *nd = value;
10141014
const NetplanDefType *type = user_data;
10151015
return nd->type == *type ? 0 : -1;
10161016
}
10171017

1018-
static gboolean
1018+
STATIC gboolean
10191019
netplan_netdef_list_write_yaml(const NetplanState* np_state, GList* netdefs, int out_fd, const char* out_fname, gboolean is_fallback, GError** error)
10201020
{
10211021
GHashTable *ovs_ports = NULL;

src/networkd.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/**
3737
* Append WiFi frequencies to wpa_supplicant's freq_list=
3838
*/
39-
static void
39+
STATIC void
4040
wifi_append_freq(__unused gpointer key, gpointer value, gpointer user_data)
4141
{
4242
GString* s = user_data;
@@ -46,7 +46,7 @@ wifi_append_freq(__unused gpointer key, gpointer value, gpointer user_data)
4646
/**
4747
* append wowlan_triggers= string for wpa_supplicant.conf
4848
*/
49-
static gboolean
49+
STATIC gboolean
5050
append_wifi_wowlan_flags(NetplanWifiWowlanFlag flag, GString* str, GError** error) {
5151
if (flag & NETPLAN_WIFI_WOWLAN_TYPES[0].flag || flag >= NETPLAN_WIFI_WOWLAN_TCP) {
5252
g_set_error(error, NETPLAN_BACKEND_ERROR, NETPLAN_ERROR_UNSUPPORTED, "ERROR: unsupported wowlan_triggers mask: 0x%x\n", flag);
@@ -65,7 +65,7 @@ append_wifi_wowlan_flags(NetplanWifiWowlanFlag flag, GString* str, GError** erro
6565
/**
6666
* Append [Match] section of @def to @s.
6767
*/
68-
static void
68+
STATIC void
6969
append_match_section(const NetplanNetDefinition* def, GString* s, gboolean match_rename)
7070
{
7171
/* Note: an empty [Match] section is interpreted as matching all devices,
@@ -105,7 +105,7 @@ append_match_section(const NetplanNetDefinition* def, GString* s, gboolean match
105105
}
106106
}
107107

108-
static void
108+
STATIC void
109109
write_bridge_params_networkd(GString* s, const NetplanNetDefinition* def)
110110
{
111111
GString *params = NULL;
@@ -131,7 +131,7 @@ write_bridge_params_networkd(GString* s, const NetplanNetDefinition* def)
131131
}
132132
}
133133

134-
static void
134+
STATIC void
135135
write_tunnel_params(GString* s, const NetplanNetDefinition* def)
136136
{
137137
GString *params = NULL;
@@ -155,7 +155,7 @@ write_tunnel_params(GString* s, const NetplanNetDefinition* def)
155155
g_string_free(params, TRUE);
156156
}
157157

158-
static void
158+
STATIC void
159159
write_wireguard_params(GString* s, const NetplanNetDefinition* def)
160160
{
161161
GString *params = NULL;
@@ -218,7 +218,7 @@ write_wireguard_params(GString* s, const NetplanNetDefinition* def)
218218
}
219219
}
220220

221-
static void
221+
STATIC void
222222
write_link_file(const NetplanNetDefinition* def, const char* rootdir, const char* path)
223223
{
224224
GString* s = NULL;
@@ -289,7 +289,7 @@ write_link_file(const NetplanNetDefinition* def, const char* rootdir, const char
289289
umask(orig_umask);
290290
}
291291

292-
static gboolean
292+
STATIC gboolean
293293
write_regdom(const NetplanNetDefinition* def, const char* rootdir, GError** error)
294294
{
295295
g_assert(def->regulatory_domain);
@@ -316,7 +316,7 @@ write_regdom(const NetplanNetDefinition* def, const char* rootdir, GError** erro
316316
}
317317

318318

319-
static gboolean
319+
STATIC gboolean
320320
interval_has_suffix(const char* param) {
321321
gchar* endptr;
322322

@@ -328,7 +328,7 @@ interval_has_suffix(const char* param) {
328328
}
329329

330330

331-
static void
331+
STATIC void
332332
write_bond_parameters(const NetplanNetDefinition* def, GString* s)
333333
{
334334
GString* params = NULL;
@@ -407,7 +407,7 @@ write_bond_parameters(const NetplanNetDefinition* def, GString* s)
407407
g_string_free(params, TRUE);
408408
}
409409

410-
static void
410+
STATIC void
411411
write_vxlan_parameters(const NetplanNetDefinition* def, GString* s)
412412
{
413413
g_assert(def->vxlan);
@@ -480,7 +480,7 @@ write_vxlan_parameters(const NetplanNetDefinition* def, GString* s)
480480
g_string_free(params, TRUE);
481481
}
482482

483-
static void
483+
STATIC void
484484
write_netdev_file(const NetplanNetDefinition* def, const char* rootdir, const char* path)
485485
{
486486
GString* s = NULL;
@@ -587,7 +587,7 @@ write_netdev_file(const NetplanNetDefinition* def, const char* rootdir, const ch
587587
umask(orig_umask);
588588
}
589589

590-
static void
590+
STATIC void
591591
write_route(NetplanIPRoute* r, GString* s)
592592
{
593593
const char *to;
@@ -622,7 +622,7 @@ write_route(NetplanIPRoute* r, GString* s)
622622
g_string_append_printf(s, "InitialAdvertisedReceiveWindow=%u\n", r->advertised_receive_window);
623623
}
624624

625-
static void
625+
STATIC void
626626
write_ip_rule(NetplanIPRule* r, GString* s)
627627
{
628628
g_string_append_printf(s, "\n[RoutingPolicyRule]\n");
@@ -642,7 +642,7 @@ write_ip_rule(NetplanIPRule* r, GString* s)
642642
g_string_append_printf(s, "TypeOfService=%d\n", r->tos);
643643
}
644644

645-
static void
645+
STATIC void
646646
write_addr_option(NetplanAddressOptions* o, GString* s)
647647
{
648648
g_string_append_printf(s, "\n[Address]\n");
@@ -659,7 +659,7 @@ write_addr_option(NetplanAddressOptions* o, GString* s)
659659
"ERROR: %s: networkd requires that %s has the same value in both " \
660660
"dhcp4_overrides and dhcp6_overrides\n"
661661

662-
static gboolean
662+
STATIC gboolean
663663
combine_dhcp_overrides(const NetplanNetDefinition* def, NetplanDHCPOverrides* combined_dhcp_overrides, GError** error)
664664
{
665665
/* if only one of dhcp4 or dhcp6 is enabled, those overrides are used */
@@ -990,7 +990,7 @@ netplan_netdef_write_network_file(
990990
return TRUE;
991991
}
992992

993-
static void
993+
STATIC void
994994
write_rules_file(const NetplanNetDefinition* def, const char* rootdir)
995995
{
996996
GString* s = NULL;
@@ -1034,7 +1034,7 @@ write_rules_file(const NetplanNetDefinition* def, const char* rootdir)
10341034
umask(orig_umask);
10351035
}
10361036

1037-
static gboolean
1037+
STATIC gboolean
10381038
append_wpa_auth_conf(GString* s, const NetplanAuthenticationSettings* auth, const char* id, GError** error)
10391039
{
10401040
switch (auth->key_management) {
@@ -1176,7 +1176,7 @@ append_wpa_auth_conf(GString* s, const NetplanAuthenticationSettings* auth, cons
11761176
}
11771177

11781178
/* netplan-feature: generated-supplicant */
1179-
static void
1179+
STATIC void
11801180
write_wpa_unit(const NetplanNetDefinition* def, const char* rootdir)
11811181
{
11821182
g_autofree gchar *stdouth = NULL;
@@ -1204,7 +1204,7 @@ write_wpa_unit(const NetplanNetDefinition* def, const char* rootdir)
12041204
umask(orig_umask);
12051205
}
12061206

1207-
static gboolean
1207+
STATIC gboolean
12081208
write_wpa_conf(const NetplanNetDefinition* def, const char* rootdir, GError** error)
12091209
{
12101210
GHashTableIter iter;

0 commit comments

Comments
 (0)