Skip to content

Commit

Permalink
Correct writeback_state sequence test (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
noursaidi committed Sep 21, 2022
1 parent 17f3f8b commit 8d6fd1b
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 32 deletions.
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 sites/udmi_site_model/out/devices/AHU-1/tests/ | xargs -I% diff -u \
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
17 changes: 15 additions & 2 deletions docs/specs/sequences/generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Check that the device MQTT-acknowledges a sent config.
Push endpoint config message to device that results in a connection error.

1. Update config:
* Add `blobset` = { "blobs": { } }
* Add `blobset` = { "blobs": { "_iot_endpoint_config": { "phase": `final`, "content_type": `application/json`, "base64": `eyAgICJwcm90b2NvbCI6ICJtcXR0IiwKICAiY2xpZW50X2lkIjogInRlc3RfcHJvamVjdC9kZXZpY2UiLAogICJob3N0bmFtZSI6ICJsb2NhbGhvc3QiCn0=` } } }
1. Wait for blobset entry config status is error

## extra_config
Expand Down 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

## endpoint_config_connection_error

Push endpoint config message to device that results in a connection error.

1. Update config:
* Add `blobset` = { "blobs": { "_iot_endpoint_config": { "phase": `final`, "content_type": `application/json`, "base64": `eyAgICJwcm90b2NvbCI6ICJtcXR0IiwKICAiY2xpZW50X2lkIjogInRlc3RfcHJvamVjdC9kZXZpY2UiLAogICJob3N0bmFtZSI6ICJsb2NhbGhvc3QiCn0=` } } }
1. Wait for blobset entry config status is error
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(
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,10 @@ 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()
|| type.isEnum()
|| Boolean.class.isAssignableFrom(type)
|| Integer.class.isAssignableFrom(type)
|| String.class.isAssignableFrom(type)
|| Date.class.isAssignableFrom(type);
}
Expand Down

0 comments on commit 8d6fd1b

Please sign in to comment.