-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add manual local Thread commission test (#48) * Remove obsolete LFS file, update file names - Commission via code, without using BLE - Use UTC time on target to ensure consistent queries regardless of local/remote timezones Inline with doc updates: canonical/matter-docs#22 --------- Co-authored-by: Mengyi Wang <[email protected]>
- Loading branch information
1 parent
b6dcc18
commit 2333f09
Showing
11 changed files
with
431 additions
and
142 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/canonical/matter-snap-testing/utils" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func InstallChipTool(t *testing.T) { | ||
const chipToolSnap = "chip-tool" | ||
|
||
// clean | ||
utils.SnapRemove(t, chipToolSnap) | ||
|
||
if utils.LocalServiceSnap() { | ||
require.NoError(t, | ||
utils.SnapInstallFromFile(nil, utils.LocalServiceSnapPath), | ||
) | ||
} else { | ||
require.NoError(t, | ||
utils.SnapInstallFromStore(nil, chipToolSnap, utils.ServiceChannel), | ||
) | ||
} | ||
t.Cleanup(func() { | ||
utils.SnapRemove(t, chipToolSnap) | ||
}) | ||
|
||
// connect interfaces | ||
utils.SnapConnect(t, chipToolSnap+":avahi-observe", "") | ||
utils.SnapConnect(t, chipToolSnap+":bluez", "") | ||
utils.SnapConnect(t, chipToolSnap+":process-control", "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package thread_tests | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/canonical/matter-snap-testing/utils" | ||
|
||
tests "chip-tool-snap-tests" | ||
) | ||
|
||
const ( | ||
otbrSnap = "openthread-border-router" | ||
OTCTL = otbrSnap + ".ot-ctl" | ||
) | ||
|
||
func setup(t *testing.T) { | ||
tests.InstallChipTool(t) | ||
|
||
const ( | ||
defaultInfraInterfaceValue = "wlan0" | ||
infraInterfaceKey = "infra-if" | ||
localInfraInterfaceEnv = "LOCAL_INFRA_IF" | ||
) | ||
|
||
// Clean | ||
utils.SnapRemove(t, otbrSnap) | ||
|
||
// Install OTBR | ||
utils.SnapInstallFromStore(t, otbrSnap, utils.ServiceChannel) | ||
t.Cleanup(func() { | ||
utils.SnapRemove(t, otbrSnap) | ||
}) | ||
|
||
// Connect interfaces | ||
snapInterfaces := []string{"avahi-control", "firewall-control", "raw-usb", "network-control", "bluetooth-control", "bluez"} | ||
for _, interfaceSlot := range snapInterfaces { | ||
utils.SnapConnect(nil, otbrSnap+":"+interfaceSlot, "") | ||
} | ||
|
||
// Set infra interface | ||
if v := os.Getenv(localInfraInterfaceEnv); v != "" { | ||
infraInterfaceValue := v | ||
utils.SnapSet(nil, otbrSnap, infraInterfaceKey, infraInterfaceValue) | ||
} else { | ||
utils.SnapSet(nil, otbrSnap, infraInterfaceKey, defaultInfraInterfaceValue) | ||
} | ||
|
||
// Start OTBR | ||
start := time.Now() | ||
utils.SnapStart(t, otbrSnap) | ||
waitForLogMessage(t, otbrSnap, "Start Thread Border Agent: OK", start) | ||
|
||
// Form Thread network | ||
utils.Exec(t, "sudo "+OTCTL+" dataset init new") | ||
utils.Exec(t, "sudo "+OTCTL+" dataset commit active") | ||
utils.Exec(t, "sudo "+OTCTL+" ifconfig up") | ||
utils.Exec(t, "sudo "+OTCTL+" thread start") | ||
utils.WaitForLogMessage(t, otbrSnap, "Thread Network", start) | ||
} | ||
|
||
func getActiveDataset(t *testing.T) string { | ||
activeDataset, _, _ := utils.Exec(t, "sudo "+OTCTL+" dataset active -x | awk '{print $NF}' | grep --invert-match \"Done\"") | ||
trimmedActiveDataset := strings.TrimSpace(activeDataset) | ||
|
||
return trimmedActiveDataset | ||
} | ||
|
||
// TODO: update the library function to print the tail before failing: | ||
// https://github.com/canonical/matter-snap-testing/blob/abae29ac5e865f0c5208350bdab63cecb3bdcc5a/utils/config.go#L54-L69 | ||
func waitForLogMessage(t *testing.T, snap, expectedLog string, since time.Time) { | ||
const maxRetry = 10 | ||
|
||
for i := 1; i <= maxRetry; i++ { | ||
time.Sleep(1 * time.Second) | ||
t.Logf("Retry %d/%d: Waiting for expected content in logs: %s", i, maxRetry, expectedLog) | ||
|
||
logs := utils.SnapLogs(t, since, snap) | ||
if strings.Contains(logs, expectedLog) { | ||
t.Logf("Found expected content in logs: %s", expectedLog) | ||
return | ||
} | ||
} | ||
|
||
t.Logf("Time out: reached max %d retries.", maxRetry) | ||
stdout, _, _ := utils.Exec(t, | ||
fmt.Sprintf("sudo journalctl --lines=10 --no-pager --unit=snap.\"%s\".otbr-agent --priority=notice", snap)) | ||
t.Log(stdout) | ||
t.FailNow() | ||
} |
Oops, something went wrong.