Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fun getAllAIGeneratedValidators(): Map<Validator, OptionValueInformation> {
Validator("config_parse_macvlan_broadcast_queue_threshold", "0") to ConfigParseMacvlanBroadcastQueueThresholdOptionValue() as OptionValueInformation,
Validator("config_parse_macvlan_mode", "0") to ConfigParseMacvlanModeOptionValue() as OptionValueInformation,
Validator("config_parse_mdi", "0") to ConfigParseMdiOptionValue() as OptionValueInformation,
Validator("config_parse_memory_pressure_watch", "0") to ConfigParseMemoryPressureWatchOptionValue() as OptionValueInformation,
Validator("config_parse_pressure_watch", "0") to ConfigParseMemoryPressureWatchOptionValue() as OptionValueInformation,
Validator("config_parse_mtu", "AF_INET6") to ConfigParseMtuOptionValue() as OptionValueInformation,
Validator("config_parse_multicast_router", "0") to ConfigParseMulticastRouterOptionValue() as OptionValueInformation,
Validator("config_parse_ndisc_start_dhcp6_client", "0") to ConfigParseNdiscStartDhcp6ClientOptionValue() as OptionValueInformation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.Simp

/**
* Validator for Swap.MemoryPressureWatch
* C Function: config_parse_memory_pressure_watch(0)
* C Function: config_parse_pressure_watch(0)
* Used by Options: Swap.MemoryPressureWatch
*
*
* Accepts boolean values (yes/no/1/0/true/false/on/off/y/n/t/f) or special values (auto/skip).
*/
class ConfigParseMemoryPressureWatchOptionValue : SimpleGrammarOptionValues(
"config_parse_memory_pressure_watch",
"config_parse_pressure_watch",
SequenceCombinator(
FlexibleLiteralChoiceTerminal("yes", "no", "1", "0", "true", "false", "on", "off", "y", "n", "t", "f", "auto", "skip"),
EOF()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,54 @@ import net.sjrx.intellij.plugins.systemdunitfiles.AbstractUnitFileTest
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.*

class SemanticDataRepositoryTest : AbstractUnitFileTest() {

/**
* Verifies that every registered validator references a function name that actually
* exists in one of the gperf files. Catches stale validators after upstream renames.
*
* Validators kept for backward compatibility with older systemd versions should be
* added to the allowlist below with a comment explaining why.
*/
fun testAllRegisteredValidatorsExistInGperfFiles() {
val sdr = SemanticDataRepository.instance

// Validators intentionally kept for backward compatibility with older systemd versions
val legacyAllowlist = setOf(
// Renamed to config_parse_unit_cpu_set in systemd; old name kept for older versions
Validator("config_parse_allowed_cpuset", "0"),
// Deprecated cgroup v1 options removed from gperf but still valid on older systemd
Validator("config_parse_cpu_shares", "0"),
Validator("config_parse_blockio_weight", "0"),
Validator("config_parse_blockio_bandwidth", "0"),
)

// Collect all Validator instances referenced in the gperf files
val gperfValidators = mutableSetOf<Validator>()
for (fileClass in FileClass.entries) {
for (section in sdr.getSectionNamesForSectionAndKey(fileClass)) {
for (key in sdr.getAllowedKeywordsInSectionFromValidators(fileClass, section)) {
gperfValidators.add(sdr.getValidatorForSectionAndKey(fileClass, section, key))
}
}
}

// Check all registered validators (not just AI-generated ones)
val registeredValidators = sdr.getValidatorMap()
val staleValidators = registeredValidators.keys.filter { validator ->
// Skip the NullOptionValue sentinel and wildcard validators — these are synthetic
// and intentionally don't correspond to gperf entries
validator.validatorName != "NULL"
&& validator.validatorArgument != "*"
&& validator !in gperfValidators
&& validator !in legacyAllowlist
}

assertTrue(
"Registered validators reference function names not found in any gperf file: " +
staleValidators.joinToString(", "),
staleValidators.isEmpty()
)
}
fun testInteresting() {
val sdr = SemanticDataRepository.instance
assertInstanceOf(sdr.getOptionValidator(FileClass.UNIT_FILE,"Socket", "SendSIGKILL"), BooleanOptionValue::class.java)
Expand Down
Loading