Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct writeback_state sequence test #450

Merged
merged 29 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
17f0676
fix writeback sequence test to work as expected
noursaidi Sep 9, 2022
13dacfd
Update generated.md
noursaidi Sep 9, 2022
1ed02c9
Adding test sequence sample out
grafnu Sep 9, 2022
40fa743
add ci check for validator/sequences
noursaidi Sep 9, 2022
37471cb
change clone_model checkout target
noursaidi Sep 12, 2022
6e76c83
Update sequence-generator to work with property maps (#15)
grafnu Sep 13, 2022
be9b7fb
new generated.md (but not comitted validator proofs)
noursaidi Sep 13, 2022
6649742
commit sequencer proofs (expect pass)
noursaidi Sep 13, 2022
6ab4205
Fixing semantic dates for discovery (#16)
grafnu Sep 13, 2022
12a967c
add sequencer output files
noursaidi Sep 13, 2022
05b93a1
sequencer.out
noursaidi Sep 13, 2022
b32f1a1
Merge branch 'master' into writeback_test1
noursaidi Sep 14, 2022
a990010
restore gcp_device_logs
noursaidi Sep 14, 2022
04357df
comments - clone model and gitattributes
noursaidi Sep 14, 2022
65d9ed5
Merge branch 'master' into writeback_test1
noursaidi Sep 20, 2022
dd55bd5
remove irrelevant log files
noursaidi Sep 20, 2022
9de2072
remove extra valid_serial_no from sequencer.out
noursaidi Sep 20, 2022
779f38a
sequencer.out
noursaidi Sep 20, 2022
f4e745b
Fix recusrion (#17)
grafnu Sep 20, 2022
99a92e7
test ci - expect failure
noursaidi Sep 20, 2022
d072d15
Merge branch 'writeback_test1' of github.com:noursaidi/udmi into writ…
noursaidi Sep 20, 2022
06d1437
flip validation directory and add generated.md
noursaidi Sep 20, 2022
5d1a6b7
generated.md extra line
noursaidi Sep 20, 2022
781955f
add endpoint_config (expect fail)
noursaidi Sep 20, 2022
d4718b4
expect pass
noursaidi Sep 20, 2022
1ecc1c2
fix
noursaidi Sep 21, 2022
9dca779
empty
noursaidi Sep 21, 2022
448b5be
add logging to ci
noursaidi Sep 21, 2022
6a81454
remove additional logging
noursaidi Sep 21, 2022
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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/gencode/** linguist-generated=true
validator/sequences/**/*.json linguist-generated=true
validator/sequences/**/*.attr linguist-generated=true
validator/sequences/**/*.log linguist-generated=true
3 changes: 3 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ jobs:
more /tmp/sequencer.out
diff -u /tmp/sequencer.out etc/sequencer.out
diff -u /tmp/generated.md docs/specs/sequences/generated.md
ls -1 validator/sequences | xargs -I% diff -u \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be warned, what I discovered the other day is that the shell in GitHub Actions doesn't always process failure conditions correctly. Did you check that this actually fails the run when there's a problem? ( You could quickly check by tweaking the validator/sequences/%/sequence.md file)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've checked and it does fail when there is a difference or missing file.

sites/udmi_site_model/out/devices/AHU-1/tests/%/sequence.md \
validator/sequences/%/sequence.md
- name: telemetry validator
env:
GCP_TARGET_PROJECT: ${{ secrets.GCP_TARGET_PROJECT }}
Expand Down
2 changes: 1 addition & 1 deletion bin/clone_model
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mkdir -p $ROOT_DIR/sites
cd $ROOT_DIR/sites

MODEL_DIR=udmi_site_model
MODEL_VER=1.7
MODEL_VER=1.8
TEST_SITE_GIT=https://github.com/faucetsdn/$MODEL_DIR.git
MODEL_REPO=origin

Expand Down
15 changes: 14 additions & 1 deletion docs/specs/sequences/generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ Check that the device correctly handles an extra out-of-schema field
1. Update config:
* Add `discovery` = { "families": { } }
1. Wait for all scans not active
1. Update config:
* Add `discovery.families.virtual` = { "generation": _family generation_, "scan_interval_sec": `10`, "enumerate": `true` }
1. Wait for scan iterations

## self_enumeration
Expand All @@ -116,6 +118,8 @@ Check that the device correctly handles an extra out-of-schema field
1. Update config:
* Add `discovery` = { "families": { } }
1. Wait for all scans not active
1. Update config:
* Add `discovery.families.virtual` = { "generation": _family generation_, "enumerate": `true` }
1. Wait for scheduled scan start
1. Wait for scan activation
1. Wait for scan completed
Expand Down Expand Up @@ -143,4 +147,13 @@ Check that the min log-level config is honored by the device.

## writeback_states

1. Test failed: Missing 'invalid' target specification
1. Wait for point filter_differential_pressure_sensor to have value_state default (null)
1. Wait for point filter_alarm_pressure_status to have value_state default (null)
1. Wait for point filter_differential_pressure_setpoint to have value_state default (null)
1. Update config:
* Add `pointset.points.filter_alarm_pressure_status.set_value` = `false`
* Set `pointset.points.filter_differential_pressure_setpoint.set_value` = `60`
* Add `pointset.points.filter_differential_pressure_sensor.set_value` = `15`
1. Wait for point filter_differential_pressure_sensor to have value_state invalid
1. Wait for point filter_alarm_pressure_status to have value_state failure
1. Wait for point filter_differential_pressure_setpoint to have value_state applied
2 changes: 1 addition & 1 deletion etc/sequencer.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ RESULT pass valid_serial_no Sequence complete
RESULT pass valid_serial_no Sequence complete
RESULT pass valid_serial_no Sequence complete
RESULT pass valid_serial_no Sequence complete
RESULT skip writeback_states Missing 'invalid' target specification
RESULT pass writeback_states Sequence complete

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion validator/bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fi

export JAVA_HOME=$JAVA_HOME_11_X64

echo Building validataor in $PWD
echo Building validator in $PWD

rm -rf build
./gradlew shadow $check $*
Expand Down
2 changes: 2 additions & 0 deletions validator/sequences/periodic_scan/sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
1. Update config:
* Add `discovery` = { "families": { } }
1. Wait for all scans not active
1. Update config:
* Add `discovery.families.virtual` = { "generation": _family generation_, "scan_interval_sec": `10`, "enumerate": `true` }
1. Wait for scan iterations
2 changes: 2 additions & 0 deletions validator/sequences/single_scan/sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
1. Update config:
* Add `discovery` = { "families": { } }
1. Wait for all scans not active
1. Update config:
* Add `discovery.families.virtual` = { "generation": _family generation_, "enumerate": `true` }
1. Wait for scheduled scan start
1. Wait for scan activation
1. Wait for scan completed
11 changes: 10 additions & 1 deletion validator/sequences/writeback_states/sequence.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

## writeback_states

1. Test failed: Missing 'invalid' target specification
1. Wait for point filter_differential_pressure_sensor to have value_state default (null)
1. Wait for point filter_alarm_pressure_status to have value_state default (null)
1. Wait for point filter_differential_pressure_setpoint to have value_state default (null)
1. Update config:
* Add `pointset.points.filter_alarm_pressure_status.set_value` = `false`
* Set `pointset.points.filter_differential_pressure_setpoint.set_value` = `60`
* Add `pointset.points.filter_differential_pressure_sensor.set_value` = `15`
1. Wait for point filter_differential_pressure_sensor to have value_state invalid
1. Wait for point filter_alarm_pressure_status to have value_state failure
1. Wait for point filter_differential_pressure_setpoint to have value_state applied
30 changes: 21 additions & 9 deletions validator/sequences/writeback_states/state_update.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void self_enumeration() {
Date startTime = SemanticDate.describe("generation start time", CleanDateFormat.cleanDate());
deviceConfig.discovery = new DiscoveryConfig();
deviceConfig.discovery.enumeration = new FamilyDiscoveryConfig();
deviceConfig.discovery.enumeration.generation = startTime;
deviceConfig.discovery.enumeration.generation =
SemanticDate.describe("generation start time", startTime);
info("Starting enumeration at " + JsonUtil.getTimestamp(startTime));
updateConfig("discovery generation");
untilTrue("enumeration generation",
Expand Down Expand Up @@ -137,7 +138,7 @@ private void initializeDiscovery() {
private void scheduleScan(Date startTime, Integer scanIntervalSec, boolean enumerate) {
info("Scan start scheduled for " + startTime);
families.forEach(family -> {
getConfigFamily(family).generation = startTime;
getConfigFamily(family).generation = SemanticDate.describe("family generation", startTime);
getConfigFamily(family).enumerate = enumerate;
getConfigFamily(family).scan_interval_sec = scanIntervalSec;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ public void writeback_states() {
deviceConfig.pointset.points.get(failurePoint).set_value = failureTarget.target_value;
deviceConfig.pointset.points.get(appliedPoint).set_value = appliedTarget.target_value;
updateConfig();

untilTrue(expectedValueState(invalidPoint, INVALID_STATE),
() -> valueStateIs(invalidPoint, INVALID_STATE)
);
untilTrue(expectedValueState(invalidPoint, FAILURE_STATE),
untilTrue(expectedValueState(failurePoint, FAILURE_STATE),
() -> valueStateIs(failurePoint, FAILURE_STATE)
);
untilTrue(expectedValueState(invalidPoint, APPLIED_STATE),
untilTrue(expectedValueState(appliedPoint, APPLIED_STATE),
() -> valueStateIs(appliedPoint, APPLIED_STATE)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.google.daq.mqtt.util;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.daq.mqtt.sequencer.semantic.SemanticValue;
Expand All @@ -25,8 +23,7 @@ public ConfigDiffEngine() {
}

/**
* Compute the changes in a config object from the previous config, as
* stored in the class.
* Compute the changes in a config object from the previous config, as stored in the class.
*
* @param deviceConfig new config
* @return list of differences against the previous config
Expand All @@ -40,16 +37,24 @@ public List<String> computeChanges(Config deviceConfig) {
return configUpdates;
}

@SuppressWarnings("unchecked")
private Map<String, Object> convertSemantics(Object thing) {
return thing == null ? ImmutableMap.of() :
Arrays.stream(thing.getClass().getFields())
.filter(field -> isNotNull(thing, field)).collect(
Collectors.toMap(Field::getName, field -> convertSemantics(thing, field)));
if (thing == null) {
return ImmutableMap.of();
}
if (thing instanceof Map) {
Map<String, Object> asMap = (Map<String, Object>) thing;
return asMap.keySet().stream()
.collect(Collectors.toMap(key -> key, key -> convertSemantics(asMap.get(key))));
}
return Arrays.stream(thing.getClass().getFields())
.filter(field -> isNotNull(thing, field)).collect(
noursaidi marked this conversation as resolved.
Show resolved Hide resolved
Collectors.toMap(Field::getName, field -> convertSemantics(thing, field)));
}

private Object convertSemantics(Object thing, Field field) {
try {
if (isBaseType(field)) {
if (isBaseType(field) || isBaseType(field.get(thing))) {
return field.get(thing);
} else {
return convertSemantics(field.get(thing));
Expand All @@ -69,7 +74,9 @@ private boolean isNotNull(Object thing, Field field) {

private boolean isBaseType(Object value) {
Class<?> type = value instanceof Field ? ((Field) value).getType() : value.getClass();
return Integer.class.isAssignableFrom(type)
return type.isPrimitive()
|| Boolean.class.isAssignableFrom(type)
|| Integer.class.isAssignableFrom(type)
|| String.class.isAssignableFrom(type)
|| Date.class.isAssignableFrom(type);
}
Expand Down