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 @@ -115,12 +115,14 @@ class SemanticDataRepository private constructor() {
validatorMap.putAll(AllowedCpuSetOptionValue.validators)
validatorMap.putAll(TtySizeOptionValue.validators)
validatorMap.putAll(ExecDirectoriesOptionValue.validators)

validatorMap.putAll(IOLimitOptionValue.validators)
validatorMap.putAll(CGWeightOptionValue.validators)
validatorMap.putAll(BlockIOWeightOptionValue.validators)
validatorMap.putAll(BlockIOBandwidthOptionValue.validators)
validatorMap.putAll(ImagePolicyOptionValue.validators)
validatorMap.putAll(CPUWeightOptionValue.validators)
validatorMap.putAll(CPUSharesOptionValue.validators)

validatorMap.putAll(CgroupSocketBindOptionValue.validators)
validatorMap.putAll(RlimitOptionValue.validators)
// Scopes are not supported since they aren't standard unit files.
fileClassToSectionNameToKeyValuesFromDoc["unit"]?.remove(SCOPE_KEYWORD)
Expand Down Expand Up @@ -543,8 +545,6 @@ unit types. These options are documented in <a href="http://man7.org/linux/man-p
else -> FileClass.UNIT_FILE
}
}


}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues

import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.Validator
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.*



class BlockIOBandwidthOptionValue() : GrammarOptionValue("config_parse_blockio_bandwidth", GRAMMAR) {

companion object {
val GRAMMAR = SequenceCombinator(OneOrMore(SequenceCombinator(DEVICE, BYTES)), EOF())

val validators = mapOf(
Validator("config_parse_blockio_bandwidth", "0") to BlockIOBandwidthOptionValue()
)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues

import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.Validator
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.*



class BlockIOWeightOptionValue() : GrammarOptionValue("config_parse_blockio_weight", GRAMMAR) {

companion object {
val GRAMMAR =
SequenceCombinator(
IntegerTerminal(10, 1001),
EOF()
)

val validators = mapOf(
Validator("config_parse_blockio_weight", "0") to BlockIOWeightOptionValue()
)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues

import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.Validator
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.*



class CGWeightOptionValue() : GrammarOptionValue("config_parse_cg_weight", GRAMMAR) {

companion object {
val GRAMMAR =
SequenceCombinator(
IntegerTerminal(1, 10001),
EOF()
)

val validators = mapOf(
Validator("config_parse_cg_weight", "0") to CGWeightOptionValue()
)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues

import kotlinx.html.ADDRESS
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.Validator
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.*



class CgroupSocketBindOptionValue() : GrammarOptionValue("config_parse_cgroup_socket_bind", GRAMMAR) {

companion object {
// https://www.freedesktop.org/software/systemd/man/latest/systemd.resource-control.html
val ADDRESS_FAMILY = LiteralChoiceTerminal("ipv4", "ipv6")
val TRANSPORT_PROTOCOL = LiteralChoiceTerminal("tcp", "udp")
val IP_PORT = IntegerTerminal(1, 65536)
val DASH = LiteralChoiceTerminal("-")
val COLON = LiteralChoiceTerminal(":")
val IP_PORT_RANGE = SequenceCombinator(IP_PORT, DASH, IP_PORT)
val IP_PORTS = AlternativeCombinator(IP_PORT_RANGE, IP_PORT)

val GRAMMAR = SequenceCombinator(
AlternativeCombinator(
LiteralChoiceTerminal("any"),
// The grammar has three blocks address-family, transport-protocol, and ip-ports, if there is more than one, there is a colon.
// We break this up into a few cases
// All specified
SequenceCombinator(ADDRESS_FAMILY, COLON, TRANSPORT_PROTOCOL,COLON, IP_PORTS),
// No ports
SequenceCombinator(ADDRESS_FAMILY, COLON, TRANSPORT_PROTOCOL),
// No transport
SequenceCombinator(ADDRESS_FAMILY, COLON, IP_PORTS),
// No Address family
SequenceCombinator(TRANSPORT_PROTOCOL,COLON, IP_PORTS),
ADDRESS_FAMILY,
TRANSPORT_PROTOCOL,
IP_PORTS
),
EOF())

val validators = mapOf(
Validator("config_parse_cgroup_socket_bind", "0") to CgroupSocketBindOptionValue()
)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar

import kotlin.math.max

/**
* Zero Or More Combinator
*/
class ZeroOrOne(val combinator : Combinator) : Combinator {

private fun match(value: String, offset: Int, f: (String, Int) -> MatchResult): MatchResult {
var index = offset
val tokens = mutableListOf<String>()
val terminals = mutableListOf<TerminalCombinator>()

var match = f(value, index)


if (match.matchResult == -1) {
return MatchResult(tokens, offset, terminals, match.longestMatch)
}

var maxLength = match.longestMatch


index = match.matchResult
tokens.addAll(match.tokens)
terminals.addAll(match.terminals)

match = f(value, index)
maxLength = max(maxLength, match.longestMatch)

return MatchResult(tokens, index, terminals, maxLength)
}

override fun SyntacticMatch(value: String, offset: Int): MatchResult {
return match(value, offset, combinator::SyntacticMatch)
}

override fun SemanticMatch(value: String, offset: Int): MatchResult {
return match(value, offset, combinator::SemanticMatch)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package net.sjrx.intellij.plugins.systemdunitfiles.inspections

import junit.framework.TestCase
import net.sjrx.intellij.plugins.systemdunitfiles.AbstractUnitFileTest

class InvalidValueInspectionForBlockIOBandwidthOptionValue : AbstractUnitFileTest() {

fun testNoWarningWhenNumberSpecifiedWithoutUnit() {
// Fixture Setup
// language="unit file (systemd)"
val file = """
[Service]
BlockIOReadBandwidth=/home 2
""".trimIndent()


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

// Verification
assertSize(0, highlights)

}

fun testNoWarningWhenNumberSpecifiedWithUnit() {
// Fixture Setup
// language="unit file (systemd)"
val file = """
[Service]
BlockIOReadBandwidth=/home 2M
""".trimIndent()


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

// Verification
assertSize(0, highlights)

}

fun testWeakWarningWhenNegativeIntegerSpecified() {
// Fixture Setup
// language="unit file (systemd)"
val file = """
[Service]
BlockIOReadBandwidth=-5
""".trimIndent()


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

// Verification
assertSize(1, highlights)
val info = highlights[0]
assertStringContains("BlockIOReadBandwidth's value does not match the expected format. Possible reasons include unrecognized characters or premature end of input.", info!!.description)
TestCase.assertEquals("-5", info.text)
}

fun testWeakWarningWhenDeviceSpecifiedWithNoValue() {
// Fixture Setup
// language="unit file (systemd)"
val file = """
[Service]
BlockIOReadBandwidth=/home
""".trimIndent()


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

// Verification
assertSize(1, highlights)
val info = highlights[0]
assertStringContains("BlockIOReadBandwidth's value does not match the expected format. Possible reasons include unrecognized characters or premature end of input.", info!!.description)
TestCase.assertEquals("/home", info.text)
}


fun testWeakWarningWhenPositiveIntegerSpecified() {
// Fixture Setup
// language="unit file (systemd)"
val file = """
[Service]
BlockIOReadBandwidth=5
""".trimIndent()


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

// Verification
assertSize(1, highlights)
val info = highlights[0]
assertStringContains("BlockIOReadBandwidth's value does not match the expected format. Possible reasons include unrecognized characters or premature end of input.", info!!.description)
TestCase.assertEquals("5", info.text)
}

}
Loading