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 @@ -74,6 +74,20 @@ class SimpleGrammarOptionValues(validatorName: String, grammar: Combinator) : Gr
FlexibleLiteralChoiceTerminal("~"),
),
EOF())),

Validator("config_parse_exec_quota", "0") to SimpleGrammarOptionValues("config_parse_exec_quota",
SequenceCombinator(
AlternativeCombinator(
OptionalWhitespacePrefix(
SequenceCombinator(IntegerTerminal(0, 4_294_967_296), OptionalWhitespacePrefix(FlexibleLiteralChoiceTerminal("K","M","G", "T"))
)),
SequenceCombinator(IntegerTerminal(0, 101), FlexibleLiteralChoiceTerminal("%")),
OptionalWhitespacePrefix(IntegerTerminal(0, 4_294_967_296)),
FlexibleLiteralChoiceTerminal("off"),
),
EOF()
))

)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,54 @@ class InvalidValueInspectionForSimpleGrammarOptionValue : AbstractUnitFileTest()
assertSize(4, highlights)
}


fun testNoWarningWhenValidQuotasAreSet() {
// Fixture Setup
// language="unit file (systemd)"
val file="""
[Service]
StateDirectoryQuota=1K
StateDirectoryQuota=1 M
StateDirectoryQuota=1T
StateDirectoryQuota=1 G
StateDirectoryQuota=0
StateDirectoryQuota=4294967295
StateDirecotryQuota=1%
StateDirecotryQuota=off
StateDirecotryQuota=100%
StateDirecotryQuota=0%
""".trimIndent()

// Execute SUT
setupFileInEditor("file.service", file)
enableInspection(InvalidValueInspection::class.java)
val highlights = myFixture.doHighlighting()

// Verification
assertSize(0, highlights)
}

fun testWarningWhenInvalidQuotasAreSet() {
// Fixture Setup
// language="unit file (systemd)"
val file="""
[Service]
StateDirectoryQuota=1P
StateDirectoryQuota=-1
StateDirectoryQuota=on
StateDirectoryQuota=allo
StateDirectoryQuota=4294967296
StateDirectoryQuota=500%
StateDirectoryQuota=5.52%
""".trimIndent()

// Execute SUT
setupFileInEditor("file.service", file)
enableInspection(InvalidValueInspection::class.java)
val highlights = myFixture.doHighlighting()

// Verification
assertSize(7, highlights)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class OptionValueTest : AbstractUnitFileTest() {
val missingValidators = hashMapOf<Validator, Int>()
var totalMissingValidators = 0
var totalFoundValidators = 0
val foundValidators = mutableSetOf<Validator>()
for (fileClass in FileClass.entries) {
for (sectionName in SemanticDataRepository.instance.getSectionNamesForFile(fileClass.fileClass)) {
for (key in SemanticDataRepository.instance.getAllowedKeywordsInSectionFromValidators(fileClass, sectionName)) {
Expand All @@ -26,6 +27,7 @@ class OptionValueTest : AbstractUnitFileTest() {
missingValidators[validator] = (missingValidators[validator] ?: 0) + 1
totalMissingValidators++
} else {
foundValidators.add(validator)
totalFoundValidators++
}
}
Expand All @@ -36,17 +38,18 @@ class OptionValueTest : AbstractUnitFileTest() {
val sortedList = missingValidatorList.sortedDescending().joinToString("\n")

println("Missing:$totalMissingValidators")
println("Missing Functions:${missingValidators.size}")
println("Found:$totalFoundValidators")

val startDate = LocalDate.of(2025, 7, 12) // Today's date
val startingCount = 1183 // Your current undocumented options count
val startDate = LocalDate.of(2025, 7, 27) // Today's date
val startingCount = 612 // Your current undocumented options count
val currentDate = LocalDate.now()
val daysSinceStart = ChronoUnit.DAYS.between(startDate, currentDate)
val reductionPerDay = 4
val reductionPerDay = 1
val allowed = maxOf(0, startingCount - (daysSinceStart * reductionPerDay))

if (totalMissingValidators >= allowed) {
assertEquals("Number of missing validators is too high at ${totalMissingValidators} > $allowed vs. found ${totalFoundValidators}", sortedList, "")
if (missingValidators.size >= allowed) {
assertEquals("Number of missing functions is too high at ${missingValidators.size} > $allowed vs. found ${foundValidators.size} ${totalFoundValidators}", sortedList, "")
}

if (totalFoundValidators == 0) {
Expand Down
Loading