public void ShouldCorrectlySetRunningMode(GenValMode genValMode) { var parameters = new ArgumentParsingTarget { RegistrationFile = genValMode == GenValMode.Generate ? new FileInfo("registration.json") : null, ResponseFile = genValMode == GenValMode.Validate ? new FileInfo("response.json") : null, AnswerFile = genValMode == GenValMode.Validate ? new FileInfo("answer.json") : null }; var result = RunningOptionsHelper.DetermineRunningMode(parameters); Assert.AreEqual(genValMode, result); }
public async Task ShouldRun(GenValMode genValMode, string registrationFile, string responseFile, string answerFile, int returnCode) { var parameters = new ArgumentParsingTarget { RegistrationFile = genValMode == GenValMode.Generate ? new FileInfo(registrationFile) : null, ResponseFile = genValMode == GenValMode.Validate ? new FileInfo(responseFile) : null, AnswerFile = genValMode == GenValMode.Validate ? new FileInfo(answerFile) : null }; var result = int.MinValue; try { _subject = new FakeGenValRunner(_fakeAutofac.GetContainer().BeginLifetimeScope()); result = await _subject.Run(parameters, genValMode); } catch (Exception e) { Console.WriteLine(e); } Assert.AreEqual(returnCode, result); }
public GenValRunningOptions(AlgoMode algoMode, GenValMode genValMode) { AlgoMode = algoMode; GenValMode = genValMode; }
/// <summary> /// Run Generation or Validation, dependent on determined run mode.. /// </summary> /// <param name="parsedParameters"></param> /// <returns></returns> public async Task <int> Run(ArgumentParsingTarget parsedParameters, GenValMode genValMode) { string errorMessage; try { switch (genValMode) { case GenValMode.Generate: { FileDirectory = Path.GetDirectoryName(parsedParameters.RegistrationFile.FullName); var registrationFile = parsedParameters.RegistrationFile.FullName; var result = await RunGeneration(registrationFile); var outputDirPath = Path.GetDirectoryName(registrationFile); if (result.Success) { // Write out the produced vector files FileService.WriteFile( Path.Combine(outputDirPath, "internalProjection.json"), result.InternalProjection, true); FileService.WriteFile( Path.Combine(outputDirPath, "prompt.json"), result.PromptProjection, true); FileService.WriteFile( Path.Combine(outputDirPath, "expectedResults.json"), result.ResultProjection, true); return((int)result.StatusCode); } // Write out the error file FileService.WriteFile( Path.Combine(outputDirPath, "error.txt"), result.ErrorMessage, true); errorMessage = $"ERROR! Generating Test Vectors for {registrationFile}: {result.ErrorMessage}"; Console.Error.WriteLine(errorMessage); Program.Logger.Error($"Status Code: {result.StatusCode}"); Program.Logger.Error(errorMessage); ErrorLogger.LogError(result.StatusCode, "generator", result.ErrorMessage, FileDirectory); return((int)result.StatusCode); } case GenValMode.Validate: { FileDirectory = Path.GetDirectoryName(parsedParameters.ResponseFile.FullName); var responseFile = parsedParameters.ResponseFile.FullName; var answerFile = parsedParameters.AnswerFile.FullName; var showExpected = parsedParameters.ShowExpected; var result = await RunValidation(responseFile, answerFile, showExpected); var outputDirPath = Path.GetDirectoryName(responseFile); if (result.Success) { // Write out the response from the validation. FileService.WriteFile( Path.Combine(outputDirPath, "validation.json"), result.ValidationResult, true); return((int)result.StatusCode); } // Write out the error file FileService.WriteFile( Path.Combine(outputDirPath, "error.txt"), result.ErrorMessage, true); errorMessage = $"ERROR! Validating Test Vectors for {responseFile}: {result.ErrorMessage}"; Console.Error.WriteLine(errorMessage); Program.Logger.Error($"Status Code: {result.StatusCode}"); Program.Logger.Error(errorMessage); ErrorLogger.LogError(result.StatusCode, "validator", result.ErrorMessage, FileDirectory); return((int)result.StatusCode); } default: errorMessage = "ERROR! Unable to find running mode"; Console.Error.WriteLine(errorMessage); return((int)StatusCode.ModeError); } } catch (Exception ex) { errorMessage = $"ERROR: {ex.Message}"; Console.WriteLine(errorMessage); Console.WriteLine(ex.StackTrace); Logger.Error($"Status Code: {StatusCode.Exception}"); Logger.Error(errorMessage); ErrorLogger.LogError(StatusCode.Exception, "driver", ex.Message, FileDirectory); return((int)StatusCode.Exception); } }
/// <summary> /// Determine the <see cref="AlgoMode"/> from the <see cref="ArgumentParsingTarget"/> and <see cref="GenValMode"/>. /// </summary> /// <param name="parsedParameters">The parsed command line arguments.</param> /// <param name="genValMode">The running mode.</param> /// <returns></returns> public static AlgoMode DetermineAlgoMode(ArgumentParsingTarget parsedParameters, GenValMode genValMode) { switch (genValMode) { case GenValMode.Generate: var parameters = JsonConvert.DeserializeObject <ParametersBase>(File.ReadAllText(parsedParameters.RegistrationFile.FullName)); return(AlgoModeLookupHelper.GetAlgoModeFromStrings(parameters.Algorithm, parameters.Mode, parameters.Revision)); case GenValMode.Validate: var internalProjection = JsonConvert.DeserializeObject <TestVectorSetBase>(File.ReadAllText(parsedParameters.AnswerFile.FullName)); return(AlgoModeLookupHelper.GetAlgoModeFromStrings(internalProjection.Algorithm, internalProjection.Mode, internalProjection.Revision)); default: throw new ArgumentException(nameof(genValMode)); } }