-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flashing: allow for different power off detection mechanisms
Allows for the selection of either ethernet carrier or serial output to detect DUT power off Change-type: minor Signed-off-by: Ryan Cooke <[email protected]>
- Loading branch information
1 parent
d2f83a6
commit 3f9dbb1
Showing
7 changed files
with
177 additions
and
102 deletions.
There are no files selected for viewing
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 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,67 @@ | ||
import { Autokit } from '../../'; | ||
import { exec } from 'mz/child_process'; | ||
import { delay } from 'bluebird'; | ||
|
||
|
||
const TIMEOUT_COUNT = Number(process.env.POWER_OFF_TIMEOUT) || 30 | ||
|
||
/** | ||
* Checks whether the DUT is powered using Ethernet carrier detection | ||
**/ | ||
async function checkDutPower(autoKit:Autokit) { | ||
const [stdout, _stderr] = await exec(`cat /sys/class/net/${autoKit.network.wiredIface}/carrier`); | ||
const file = stdout.toString(); | ||
if (file.includes('1')) { | ||
console.log(`DUT is currently On`); | ||
return true; | ||
} else { | ||
console.log(`DUT is currently Off`); | ||
return false; | ||
} | ||
} | ||
|
||
export async function waitForPowerOffEthernet(autoKit:Autokit):Promise<void>{ | ||
// dut will now internally flash - need to wait until we detect DUT has powered off | ||
// FOR NOW: use the network | ||
// check if the DUT is on first | ||
let dutOn = false; | ||
while (!dutOn) { | ||
console.log(`waiting for DUT to be on`); | ||
dutOn = await checkDutPower(autoKit); | ||
await delay(1000 * 5); // 5 seconds between checks | ||
} | ||
|
||
const POLL_INTERVAL = 1000; // 1 second | ||
const POLL_TRIES = 20; // 20 tries | ||
let attempt = 0; | ||
await delay(1000 * 60); | ||
while (dutOn) { | ||
await delay(1000 * 10); // 10 seconds between checks | ||
console.log(`waiting for DUT to be off`); | ||
dutOn = await checkDutPower(autoKit); | ||
// occasionally the DUT might appear to be powered down, but it isn't - we want to confirm that the DUT has stayed off for an interval of time | ||
if (!dutOn) { | ||
let offCount = 0; | ||
console.log(`detected DUT has powered off - confirming...`); | ||
for (let tries = 0; tries < POLL_TRIES; tries++) { | ||
await delay(POLL_INTERVAL); | ||
dutOn = await checkDutPower(autoKit); | ||
if (!dutOn) { | ||
offCount += 1; | ||
} | ||
} | ||
console.log( | ||
`DUT stayed off for ${offCount} checks, expected: ${POLL_TRIES}`, | ||
); | ||
if (offCount !== POLL_TRIES) { | ||
// if the DUT didn't stay off, then we must try the loop again | ||
dutOn = true; | ||
} | ||
} | ||
attempt += 1; | ||
if (attempt === TIMEOUT_COUNT){ | ||
await autoKit.power.off(); | ||
throw new Error(`Timed out while trying to flash internal storage!!. Powered off DUT.`) | ||
} | ||
} | ||
} |
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,15 @@ | ||
import { Autokit } from "../.."; | ||
import { waitForPowerOffEthernet } from "./ethernet"; | ||
import { waitForPowerOffSerial } from "./serial"; | ||
|
||
const powerOffSelector = process.env.POWER_OFF_SELECTOR || 'ethernet' | ||
|
||
const powerOffFunctions: {[key: string]: (autoKit: Autokit) => Promise<void> } = { | ||
ethernet: waitForPowerOffEthernet, | ||
serial: waitForPowerOffSerial, | ||
}; | ||
|
||
const waitForPowerOff = powerOffFunctions[powerOffSelector]; | ||
|
||
|
||
export { waitForPowerOff } |
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,37 @@ | ||
import { Autokit } from '../../'; | ||
import { ReadlineParser } from '@serialport/parser-readline'; | ||
import { Readable } from 'serialport'; | ||
|
||
const powerOffMessage = process.env.POWER_OFF_MESSAGE || 'reboot: Power down' | ||
const timeout = Number(process.env.POWER_OFF_TIMEOUT) || 1000*60*5; | ||
|
||
/** | ||
* Checks whether the DUT has powered down by checking for a serial message | ||
**/ | ||
export async function waitForPowerOffSerial(autoKit:Autokit):Promise<void> { | ||
const serialport = await autoKit.serial.open(); | ||
|
||
if(serialport !== undefined){ | ||
return new Promise<void>((resolve, reject) => { | ||
|
||
let timer = setTimeout(async () => { | ||
await autoKit.serial.close(); | ||
reject(`Timed out while waiting for power down message over serial!`); | ||
}, timeout) | ||
|
||
// Examine each line of the serial output from the DUT as it comes in | ||
const parser = serialport.pipe(new ReadlineParser({ delimiter: '\n' })); | ||
parser.on('data', async(data:string) => { | ||
console.log(`Serial line: ${data.toString()}`); | ||
if(data.toString().includes(powerOffMessage)){ | ||
console.log(`### Detected power off message ###`) | ||
await autoKit.power.off(); | ||
await autoKit.serial.close(); | ||
clearTimeout(timer); | ||
resolve(); | ||
} | ||
}) | ||
}) | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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