Skip to content

Commit

Permalink
ctests: stop including C files in the test files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
daniloegea committed Jan 16, 2024
1 parent 780e8c7 commit 5d30624
Show file tree
Hide file tree
Showing 23 changed files with 292 additions and 315 deletions.
6 changes: 3 additions & 3 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Loading and error handling
****************************************************/

static void
STATIC void
write_error_marker(GString *message, int column)
{
int i;
Expand All @@ -42,7 +42,7 @@ write_error_marker(GString *message, int column)
g_string_append_printf(message, "^");
}

static char *
STATIC char *
get_syntax_error_context(const NetplanParser* npp, const int line_num, const int column, GError **error)
{
GString *message = NULL;
Expand Down Expand Up @@ -72,7 +72,7 @@ get_syntax_error_context(const NetplanParser* npp, const int line_num, const int
return g_string_free(message, FALSE);
}

static char *
STATIC char *
get_parser_error_context(const yaml_parser_t *parser, __unused GError **error)
{
GString *message = NULL;
Expand Down
10 changes: 10 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ libnetplan = library(
soversion: '0.0',
install: true)

libnetplan_testing = library(
'netplan_testing',
sources,
gnu_symbol_visibility: 'default',
c_args: ['-DUNITTESTS'],
dependencies: [glib, gio, yaml, uuid],
include_directories: inc,
soversion: '0.0',
install: false)

libexec_netplan = join_paths(get_option('libexecdir'), 'netplan')
executable(
'generate',
Expand Down
36 changes: 18 additions & 18 deletions src/netplan.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ gchar *tmp = NULL;

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

static gboolean
STATIC gboolean
write_match(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
{
YAML_SCALAR_PLAIN(event, emitter, "match");
Expand All @@ -121,7 +121,7 @@ write_match(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefini
err_path: return FALSE; // LCOV_EXCL_LINE
}

static gboolean
STATIC gboolean
write_auth(yaml_event_t* event, yaml_emitter_t* emitter, NetplanAuthenticationSettings auth)
{
YAML_SCALAR_PLAIN(event, emitter, "auth");
Expand All @@ -145,7 +145,7 @@ write_auth(yaml_event_t* event, yaml_emitter_t* emitter, NetplanAuthenticationSe
err_path: return FALSE; // LCOV_EXCL_LINE
}

static gboolean
STATIC gboolean
write_bond_params(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
{
if (DIRTY(def, def->bond_params)
Expand Down Expand Up @@ -205,7 +205,7 @@ write_bond_params(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNet
err_path: return FALSE; // LCOV_EXCL_LINE
}

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

static gboolean
STATIC gboolean
write_bridge_params(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def, const GArray *interfaces)
{
if (def->custom_bridging || DIRTY_COMPLEX(def, def->bridge_params)) {
Expand Down Expand Up @@ -316,7 +316,7 @@ write_bridge_params(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanN
err_path: return FALSE; // LCOV_EXCL_LINE
}

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

static void
STATIC void
_passthrough_handler(GQuark key_id, gpointer value, gpointer user_data)
{
_passthrough_handler_data *d = user_data;
Expand All @@ -348,7 +348,7 @@ _passthrough_handler(GQuark key_id, gpointer value, gpointer user_data)
err_path: return; // LCOV_EXCL_LINE
}

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

static gboolean
STATIC gboolean
write_access_points(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
{
NetplanWifiAccessPoint* ap = NULL;
Expand Down Expand Up @@ -407,7 +407,7 @@ write_access_points(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanN
err_path: return FALSE; // LCOV_EXCL_LINE
}

static gboolean
STATIC gboolean
write_addresses(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
{
YAML_SCALAR_PLAIN(event, emitter, "addresses");
Expand Down Expand Up @@ -438,7 +438,7 @@ write_addresses(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDe
err_path: return FALSE; // LCOV_EXCL_LINE
}

static gboolean
STATIC gboolean
write_nameservers(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
{
YAML_SCALAR_PLAIN(event, emitter, "nameservers");
Expand Down Expand Up @@ -470,7 +470,7 @@ write_nameservers(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNet
err_path: return FALSE; // LCOV_EXCL_LINE
}

static gboolean
STATIC gboolean
write_dhcp_overrides(yaml_event_t* event, yaml_emitter_t* emitter, const char* key, const NetplanNetDefinition* def, const NetplanDHCPOverrides* data)
{
if (DIRTY_COMPLEX(def, *data)
Expand Down Expand Up @@ -500,7 +500,7 @@ write_dhcp_overrides(yaml_event_t* event, yaml_emitter_t* emitter, const char* k
err_path: return FALSE; // LCOV_EXCL_LINE
}

static gboolean
STATIC gboolean
write_tunnel_settings(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
{
YAML_NONNULL_STRING(event, emitter, "mode", netplan_tunnel_mode_name(def->tunnel.mode));
Expand Down Expand Up @@ -573,7 +573,7 @@ write_tunnel_settings(yaml_event_t* event, yaml_emitter_t* emitter, const Netpla
err_path: return FALSE; // LCOV_EXCL_LINE
}

static gboolean
STATIC gboolean
write_routes(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def)
{
if (def->routes && def->routes->len > 0) {
Expand Down Expand Up @@ -625,7 +625,7 @@ write_routes(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefin
err_path: return FALSE; // LCOV_EXCL_LINE
}

static gboolean
STATIC gboolean
write_openvswitch(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanOVSSettings* ovs, NetplanBackend backend, GHashTable *ovs_ports)
{
GHashTableIter iter;
Expand Down Expand Up @@ -714,7 +714,7 @@ write_openvswitch(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanOVS
err_path: return FALSE; // LCOV_EXCL_LINE
}

static void
STATIC void
_serialize_yaml(
const NetplanState* np_state,
yaml_event_t* event,
Expand Down Expand Up @@ -1007,15 +1007,15 @@ netplan_netdef_write_yaml(
// LCOV_EXCL_STOP
}

static int
STATIC int
contains_netdef_type(gconstpointer value, gconstpointer user_data)
{
const NetplanNetDefinition *nd = value;
const NetplanDefType *type = user_data;
return nd->type == *type ? 0 : -1;
}

static gboolean
STATIC gboolean
netplan_netdef_list_write_yaml(const NetplanState* np_state, GList* netdefs, int out_fd, const char* out_fname, gboolean is_fallback, GError** error)
{
GHashTable *ovs_ports = NULL;
Expand Down
40 changes: 20 additions & 20 deletions src/networkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/**
* Append WiFi frequencies to wpa_supplicant's freq_list=
*/
static void
STATIC void
wifi_append_freq(__unused gpointer key, gpointer value, gpointer user_data)
{
GString* s = user_data;
Expand All @@ -46,7 +46,7 @@ wifi_append_freq(__unused gpointer key, gpointer value, gpointer user_data)
/**
* append wowlan_triggers= string for wpa_supplicant.conf
*/
static gboolean
STATIC gboolean
append_wifi_wowlan_flags(NetplanWifiWowlanFlag flag, GString* str, GError** error) {
if (flag & NETPLAN_WIFI_WOWLAN_TYPES[0].flag || flag >= NETPLAN_WIFI_WOWLAN_TCP) {
g_set_error(error, NETPLAN_BACKEND_ERROR, NETPLAN_ERROR_UNSUPPORTED, "ERROR: unsupported wowlan_triggers mask: 0x%x\n", flag);
Expand All @@ -65,7 +65,7 @@ append_wifi_wowlan_flags(NetplanWifiWowlanFlag flag, GString* str, GError** erro
/**
* Append [Match] section of @def to @s.
*/
static void
STATIC void
append_match_section(const NetplanNetDefinition* def, GString* s, gboolean match_rename)
{
/* Note: an empty [Match] section is interpreted as matching all devices,
Expand Down Expand Up @@ -105,7 +105,7 @@ append_match_section(const NetplanNetDefinition* def, GString* s, gboolean match
}
}

static void
STATIC void
write_bridge_params_networkd(GString* s, const NetplanNetDefinition* def)
{
GString *params = NULL;
Expand All @@ -131,7 +131,7 @@ write_bridge_params_networkd(GString* s, const NetplanNetDefinition* def)
}
}

static void
STATIC void
write_tunnel_params(GString* s, const NetplanNetDefinition* def)
{
GString *params = NULL;
Expand All @@ -155,7 +155,7 @@ write_tunnel_params(GString* s, const NetplanNetDefinition* def)
g_string_free(params, TRUE);
}

static void
STATIC void
write_wireguard_params(GString* s, const NetplanNetDefinition* def)
{
GString *params = NULL;
Expand Down Expand Up @@ -218,7 +218,7 @@ write_wireguard_params(GString* s, const NetplanNetDefinition* def)
}
}

static void
STATIC void
write_link_file(const NetplanNetDefinition* def, const char* rootdir, const char* path)
{
GString* s = NULL;
Expand Down Expand Up @@ -289,7 +289,7 @@ write_link_file(const NetplanNetDefinition* def, const char* rootdir, const char
umask(orig_umask);
}

static gboolean
STATIC gboolean
write_regdom(const NetplanNetDefinition* def, const char* rootdir, GError** error)
{
g_assert(def->regulatory_domain);
Expand All @@ -316,7 +316,7 @@ write_regdom(const NetplanNetDefinition* def, const char* rootdir, GError** erro
}


static gboolean
STATIC gboolean
interval_has_suffix(const char* param) {
gchar* endptr;

Expand All @@ -328,7 +328,7 @@ interval_has_suffix(const char* param) {
}


static void
STATIC void
write_bond_parameters(const NetplanNetDefinition* def, GString* s)
{
GString* params = NULL;
Expand Down Expand Up @@ -407,7 +407,7 @@ write_bond_parameters(const NetplanNetDefinition* def, GString* s)
g_string_free(params, TRUE);
}

static void
STATIC void
write_vxlan_parameters(const NetplanNetDefinition* def, GString* s)
{
g_assert(def->vxlan);
Expand Down Expand Up @@ -480,7 +480,7 @@ write_vxlan_parameters(const NetplanNetDefinition* def, GString* s)
g_string_free(params, TRUE);
}

static void
STATIC void
write_netdev_file(const NetplanNetDefinition* def, const char* rootdir, const char* path)
{
GString* s = NULL;
Expand Down Expand Up @@ -587,7 +587,7 @@ write_netdev_file(const NetplanNetDefinition* def, const char* rootdir, const ch
umask(orig_umask);
}

static void
STATIC void
write_route(NetplanIPRoute* r, GString* s)
{
const char *to;
Expand Down Expand Up @@ -622,7 +622,7 @@ write_route(NetplanIPRoute* r, GString* s)
g_string_append_printf(s, "InitialAdvertisedReceiveWindow=%u\n", r->advertised_receive_window);
}

static void
STATIC void
write_ip_rule(NetplanIPRule* r, GString* s)
{
g_string_append_printf(s, "\n[RoutingPolicyRule]\n");
Expand All @@ -642,7 +642,7 @@ write_ip_rule(NetplanIPRule* r, GString* s)
g_string_append_printf(s, "TypeOfService=%d\n", r->tos);
}

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

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

static void
STATIC void
write_rules_file(const NetplanNetDefinition* def, const char* rootdir)
{
GString* s = NULL;
Expand Down Expand Up @@ -1034,7 +1034,7 @@ write_rules_file(const NetplanNetDefinition* def, const char* rootdir)
umask(orig_umask);
}

static gboolean
STATIC gboolean
append_wpa_auth_conf(GString* s, const NetplanAuthenticationSettings* auth, const char* id, GError** error)
{
switch (auth->key_management) {
Expand Down Expand Up @@ -1176,7 +1176,7 @@ append_wpa_auth_conf(GString* s, const NetplanAuthenticationSettings* auth, cons
}

/* netplan-feature: generated-supplicant */
static void
STATIC void
write_wpa_unit(const NetplanNetDefinition* def, const char* rootdir)
{
g_autofree gchar *stdouth = NULL;
Expand Down Expand Up @@ -1204,7 +1204,7 @@ write_wpa_unit(const NetplanNetDefinition* def, const char* rootdir)
umask(orig_umask);
}

static gboolean
STATIC gboolean
write_wpa_conf(const NetplanNetDefinition* def, const char* rootdir, GError** error)
{
GHashTableIter iter;
Expand Down
Loading

0 comments on commit 5d30624

Please sign in to comment.