Created
November 29, 2016 20:21
-
-
Save djmunro/85824aa1b85a11de62c0d8dafd0cf5fd to your computer and use it in GitHub Desktop.
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
using System; | |
using System.IO; | |
using Harman.Generic.Framework; | |
namespace Harman.GM.Info3.TestSupport.Extended | |
{ | |
public enum Waveband | |
{ | |
Fm, | |
Am, | |
Lw, | |
Sw, | |
Wb | |
} | |
public enum RegionalizationMode | |
{ | |
Off, | |
Fast, | |
Normal, | |
Slow, | |
On | |
} | |
public enum SeekStatus | |
{ | |
SeekStatusStop, | |
SeekStatusUp, | |
SeekStatusDown, | |
ScanStatusUp, | |
ScanStatusDown | |
} | |
public enum AudioStatus | |
{ | |
Ready, | |
Initializing, | |
Unavailable | |
} | |
public enum HdStatus | |
{ | |
AnalogAudio, | |
Buffering, | |
DigitalAuido, | |
Off, | |
BallgameMode, | |
Uninitialized | |
} | |
public class RegionCodeInfo | |
{ | |
public string AmLower { get; set; } | |
public string AmStep { get; set; } | |
public string AmUpper { get; set; } | |
public string FmLower { get; set; } | |
public string FmStep { get; set; } | |
public string FmUpper { get; set; } | |
public string LwLower { get; set; } | |
public string LwStep { get; set; } | |
public string LwUpper { get; set; } | |
public string SwLower { get; set; } | |
public string SwStep { get; set; } | |
public string SwUpper { get; set; } | |
public string RegInfoCode { get; set; } | |
} | |
public abstract class HTunerCase : TestCase | |
{ | |
private static readonly string RemoteHTestToolsDir = "/data/htest/tools/"; | |
private static readonly string DriverFailedPattern = "[FAILED]"; | |
private readonly string _binaryName; | |
private readonly string _tunerDriverPath; | |
private string _remotePath; | |
protected HTunerCase(string name, string tunerDriverPath) | |
{ | |
_tunerDriverPath = tunerDriverPath; | |
_binaryName = Path.GetFileName(tunerDriverPath); | |
Name = name; | |
} | |
public override void Precondition() | |
{ | |
if (!ADBManager.WaitForDevice()) | |
throw new TestCaseFailure("Failed to wait for ADB!"); | |
_remotePath = Path.Combine(RemoteHTestToolsDir, _binaryName); | |
if (ADBManager.UpdateFile(_tunerDriverPath, _remotePath)) | |
ADBManager.ShellCommand("chmod +x " + _remotePath, true); | |
} | |
public string FormatEnum(Enum enm, string format = "G") | |
{ | |
return enm.ToString(format).ToUpper(); | |
} | |
public bool Tune(int frequency, int subchannel) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, | |
$"[TunerDriver] Tuning to frequency={frequency}, subchannel={subchannel}"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} Tune {frequency} {subchannel}")); | |
} | |
public bool Seek(string direction) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Seeking {direction}"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} Seek {direction}")); | |
} | |
public bool FastSeek(string direction) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Fast seek, direction={direction}"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} FastSeek {direction}")); | |
} | |
public bool FastStep(string direction) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Fast step, direction={direction}"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} FastStep {direction}")); | |
} | |
public bool Step(string direction) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Step {direction}"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} Step {direction}")); | |
} | |
public bool SeekDarc(string mode) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Seeking Darc, mode={mode}"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} SeekDarc {mode}")); | |
} | |
public bool TuneDarc(int frequency) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Tuning Darc, frequency={frequency}"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} TuneDarc {frequency}")); | |
} | |
public bool ResetFactoryDefaults() | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Resetting to factory defaults"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} ResetFactoryDefaults")); | |
} | |
public bool UpdateStationList() | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Updating station list"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} UpdateStationList")); | |
} | |
public bool CancelStationListUpdate() | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Cancelling updating station list"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} CancelStationListUpdate")); | |
} | |
public bool SetConfiguration(Waveband waveband, int frequency, int subchannel) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, | |
$"[TunerDriver] Setting Configuration, frequency={frequency}, subchannel={subchannel}"); | |
return | |
ProcessResult( | |
ADBManager.ShellCommand( | |
$"{_remotePath} SetConfiguration {FormatEnum(waveband)} {frequency} {subchannel}")); | |
} | |
public bool SetWaveband(Waveband waveband) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, | |
$"[TunerDriver] Setting waveband to {FormatEnum(waveband)}"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} SetWaveband {FormatEnum(waveband)}")); | |
} | |
public bool SetStationById(int id) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Setting station by id, id={id}"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} SetStationById {id}")); | |
} | |
public bool SetRegionalizationMode(RegionalizationMode mode) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, | |
$"[TunerDriver] Setting regionalization mode, mode={FormatEnum(mode)}"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} SetRegionalizationMode {FormatEnum(mode)}")); | |
} | |
public bool SetPtyFilter(string filter) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Setting pty filter, filter={filter}"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} SetPtyFilter {filter}")); | |
} | |
public bool SetPtyListFilter(string filter) | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Setting pty list filter, filter={filter}"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} SetPtyListFilter {filter}")); | |
} | |
public bool StopFastStepOrSeek() | |
{ | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Stopping fast step / fast seek"); | |
return ProcessResult(ADBManager.ShellCommand($"{_remotePath} StopFastStepOrSeek")); | |
} | |
public Waveband GetWaveband() | |
{ | |
var waveband = ProcessGetResult(ADBManager.ShellCommand($"{_remotePath} GetWaveband")); | |
switch (waveband) | |
{ | |
case "AM": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Waveband is Am"); | |
return Waveband.Am; | |
case "FM": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Waveband is Fm"); | |
return Waveband.Fm; | |
case "LW": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Waveband is Lw"); | |
return Waveband.Lw; | |
case "SW": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Waveband is Sw"); | |
return Waveband.Sw; | |
case "WB": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Waveband is Wb"); | |
return Waveband.Wb; | |
case "ERROR": | |
throw new TestCaseFailure("[TunerDriver] tuner_get_waveband(&waveband) != PAL_SUCCESS"); | |
default: | |
throw new TestCaseFailure($"Invalid waveband, waveband={waveband}"); | |
} | |
} | |
public SeekStatus GetSeekStatus() | |
{ | |
var seekStatus = ProcessGetResult(ADBManager.ShellCommand($"{_remotePath} GetSeekStatus")); | |
switch (seekStatus) | |
{ | |
case "SEEK_STATUS_STOP": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Seek status is SEEK_STATUS_STOP"); | |
return SeekStatus.SeekStatusStop; | |
case "SEEK_STATUS_UP": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Seek status is SEEK_STATUS_UP"); | |
return SeekStatus.SeekStatusUp; | |
case "SEEK_STATUS_DOWN": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Seek status is SEEK_STATUS_DOWN"); | |
return SeekStatus.SeekStatusDown; | |
case "SCAN_STATUS_UP": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Seek status is SCAN_STATUS_UP"); | |
return SeekStatus.ScanStatusUp; | |
case "SCAN_STATUS_DOWN": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Seek status is SCAN_STATUS_DOWN"); | |
return SeekStatus.ScanStatusDown; | |
case "ERROR": | |
throw new TestCaseFailure("[TunerDriver] tuner_get_seek_status(&status) != PAL_SUCCESS"); | |
default: | |
throw new TestCaseFailure($"Invalid seek status, status={seekStatus}"); | |
} | |
} | |
public AudioStatus GetAudioStatus() | |
{ | |
var audioStatus = ProcessGetResult(ADBManager.ShellCommand($"{_remotePath} GetAudioStatus")); | |
switch (audioStatus) | |
{ | |
case "READY": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Audio status is READY"); | |
return AudioStatus.Ready; | |
case "INITIALIZING": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Audio status is INITIALIZING"); | |
return AudioStatus.Initializing; | |
case "UNAVAILABLE": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Audio status is UNAVAILABLE"); | |
return AudioStatus.Unavailable; | |
case "ERROR": | |
throw new TestCaseFailure("[TunerDriver] tuner_get_audio_status(&status) != PAL_SUCCESS"); | |
default: | |
throw new TestCaseFailure($"Invalid audio status, status = {audioStatus}"); | |
} | |
} | |
public string GetAvailableWavebands() | |
{ | |
var wavebands = ProcessGetResult(ADBManager.ShellCommand($"{_remotePath} GetAvailableWavebands")); | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Waveband: {wavebands}"); | |
return wavebands; | |
} | |
public string GetHdProgramsAvailable() | |
{ | |
var hdPrograms = ProcessGetResult(ADBManager.ShellCommand($"{_remotePath} GetHdProgramsAvailable")); | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Hd Programs: {hdPrograms}"); | |
return hdPrograms; | |
} | |
public HdStatus GetHdStatus() | |
{ | |
var hdStatus = ProcessGetResult(ADBManager.ShellCommand($"{_remotePath} GetHdStatus")); | |
switch (hdStatus) | |
{ | |
case "ANALOG_AUDIO": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Hd status is ANALOG_AUDIO"); | |
return HdStatus.AnalogAudio; | |
case "BUFFERING": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Hd status is BUFFERING"); | |
return HdStatus.Buffering; | |
case "DIGITAL_AUIDO": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Hd status is DIGITAL_AUIDO"); | |
return HdStatus.DigitalAuido; | |
case "OFF": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Hd status is OFF"); | |
return HdStatus.Off; | |
case "BALLGAME_MODE": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Hd status is BALLGAME_MODE"); | |
return HdStatus.BallgameMode; | |
case "UNINITIALIZED": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] Hd status is UNINITIALIZED"); | |
return HdStatus.Uninitialized; | |
case "ERROR": | |
throw new TestCaseFailure("[TunerDriver] tuner_get_hd_status(&status) != PAL_SUCCESS"); | |
default: | |
throw new TestCaseFailure($"Invalid Hd status, status = {hdStatus}"); | |
} | |
} | |
public string GetJapanAmTrafficChannels() | |
{ | |
var japanAmTrafficChannels = | |
ProcessGetResult(ADBManager.ShellCommand($"{_remotePath} GetJapanAmTrafficChannels")); | |
TestConsole.LogMessage(TestConsoleLevel.Info, | |
$"[TunerDriver] Japan AM traffic channels: {japanAmTrafficChannels}"); | |
return japanAmTrafficChannels; | |
} | |
public string GetRdsTime() | |
{ | |
var rdsTime = ProcessGetResult(ADBManager.ShellCommand($"{_remotePath} GetRdsTime")); | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Rds time: {rdsTime}"); | |
return rdsTime; | |
} | |
public RegionalizationMode GetRegionalizationMode() | |
{ | |
var regionalizationMode = ProcessGetResult(ADBManager.ShellCommand($"{_remotePath} GetRegionalizationMode")); | |
switch (regionalizationMode) | |
{ | |
case "OFF": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] RegionalizationMode is Off"); | |
return RegionalizationMode.Off; | |
case "FAST": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] RegionalizationMode is Fast"); | |
return RegionalizationMode.Fast; | |
case "NORMAL": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] RegionalizationMode is Normal"); | |
return RegionalizationMode.Normal; | |
case "SLOW": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] RegionalizationMode is Slow"); | |
return RegionalizationMode.Slow; | |
case "ON": | |
TestConsole.LogMessage(TestConsoleLevel.Info, "[TunerDriver] RegionalizationMode is On"); | |
return RegionalizationMode.On; | |
case "ERROR": | |
throw new TestCaseFailure("[TunerDriver] tuner_get_regionalization_mode(&mode) != PAL_SUCCESS"); | |
default: | |
throw new TestCaseFailure($"Invalid regionalization mode, mode={regionalizationMode}"); | |
} | |
} | |
public bool GetStereoState() | |
{ | |
var stereoState = ProcessResult(ADBManager.ShellCommand($"{_remotePath} GetStereoState")); | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Stereo state is {stereoState}"); | |
return stereoState; | |
} | |
public string GetRadioText() | |
{ | |
var radioText = ProcessGetResult(ADBManager.ShellCommand($"{_remotePath} GetRadioText")); | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Radio text is {radioText}"); | |
return radioText; | |
} | |
public string GetRadioTextPlus() | |
{ | |
var radioTextPlus = ProcessGetResult(ADBManager.ShellCommand($"{_remotePath} GetRadioTextPlus")); | |
TestConsole.LogMessage(TestConsoleLevel.Info, $"[TunerDriver] Radio text plus is {radioTextPlus}"); | |
return radioTextPlus; | |
} | |
public RegionCodeInfo GetRegionCodeInfo() | |
{ | |
var regCode = new RegionCodeInfo(); | |
var info = ProcessGetResult(ADBManager.ShellCommand($"{_remotePath} GetRegionCodeInfo")); | |
var data = info.Split(','); | |
foreach (var item in data) | |
{ | |
var pair = item.Split(':'); | |
var key = pair[0]; | |
var value = pair[1]; | |
switch (key) | |
{ | |
case "amLower": | |
regCode.AmLower = value; | |
break; | |
case "amStep": | |
regCode.AmStep = value; | |
break; | |
case "amUpper": | |
regCode.AmUpper = value; | |
break; | |
case "fmLower": | |
regCode.FmLower = value; | |
break; | |
case "fmStep": | |
regCode.FmStep = value; | |
break; | |
case "fmUpper": | |
regCode.FmUpper = value; | |
break; | |
case "lwLower": | |
regCode.LwLower = value; | |
break; | |
case "lwStep": | |
regCode.LwStep = value; | |
break; | |
case "lwUpper": | |
regCode.LwUpper = value; | |
break; | |
case "swLower": | |
regCode.SwLower = value; | |
break; | |
case "swStep": | |
regCode.SwStep = value; | |
break; | |
case "swUpper": | |
regCode.SwUpper = value; | |
break; | |
case "regInfoCode": | |
regCode.RegInfoCode = value; | |
break; | |
default: | |
throw new Exception("Not implemented" + key); | |
} | |
} | |
return regCode; | |
} | |
private static bool ProcessResult(ExecuteResult result) | |
{ | |
if ((result == null) || (result.ExitCode != 0)) | |
return false; | |
if (((result.Output != null) && result.Output.Contains(DriverFailedPattern)) | |
|| ((result.ErrorOutput != null) && result.ErrorOutput.Contains(DriverFailedPattern))) | |
return false; | |
return true; | |
} | |
private static string ProcessGetResult(ExecuteResult result) | |
{ | |
var resp = "ERR"; | |
if (result.Output != null) | |
resp = result.Output.Replace("HTest TunerDriver v0.1", ""); | |
return resp.Trim(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment