blob: 16e0ccd48473cc340ee087d3f5f74bb94933a372 [file] [log] [blame]
Yong Hongcb45e082019-01-30 18:55:16 +08001/* Copyright 2019 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6#ifndef HARDWARE_VERIFIER_CLI_H_
7#define HARDWARE_VERIFIER_CLI_H_
8
9#include <memory>
10#include <ostream>
11#include <string>
12
13#include <base/macros.h>
14
15#include "hardware_verifier/hw_verification_spec_getter.h"
16#include "hardware_verifier/probe_result_getter.h"
17#include "hardware_verifier/verifier.h"
18
19namespace hardware_verifier {
20
21enum CLIVerificationResult {
22 kPass = 0,
23
24 // The whole process works without errors, but the verification
25 // report shows the device is not compliant.
26 kFail,
27
28 // Failed to load the probe result from the specific file.
29 kInvalidProbeResultFile,
30
31 // Failed to load the verification payload from either the default one
32 // or the specific one.
33 kInvalidHwVerificationSpecFile,
34
35 // The |runtime_probe| fails to return a valid probe result.
36 kProbeFail,
37
38 // Content in the verification payload and the probe result are not matched
39 // to each other.
40 kProbeResultHwVerificationSpecMisalignment,
41
42 kUnknownError
43};
44
45enum CLIOutputFormat {
Yong Hong8d168b02019-05-23 19:54:23 +080046 kProtoBin, // Protobuf binary format.
Yong Hong85a4dff2019-05-25 04:22:47 +080047 kText // Human readable text format for debug purpose.
Yong Hongcb45e082019-01-30 18:55:16 +080048};
49
50// A class that holds the core logic of the program if runs in CLI mode.
51class CLI {
52 public:
53 // Constructor, it sets the dependent classes to the default implementation.
54 CLI();
Qijiang Fan6bc59e12020-11-11 02:51:06 +090055 CLI(const CLI&) = delete;
56 CLI& operator=(const CLI&) = delete;
Yong Hongcb45e082019-01-30 18:55:16 +080057
58 // Verifies the probe result with the verification payload and then outputs
59 // the report.
60 //
61 // @param probe_result_file: Path to the file that contains the probe result.
62 // If the string is empty, it invokes |runtime_probe| to get the probe
63 // result.
64 // @param hw_verification_spec_file: Path to the file that contains the
65 // verification payload. If the string is empty, it reads the default
66 // verification payload file in the rootfs.
67 // @param output_format: The format of the output data.
Kevin Linef321a52020-09-01 18:31:52 +080068 // @param pii: Output result including PII data like UUID and generic device
69 // info.
Yong Hongcb45e082019-01-30 18:55:16 +080070 //
71 // @return Execution result, can be either the verification result or the
72 // failure code.
73 CLIVerificationResult Run(const std::string& probe_result_file,
74 const std::string& hw_verification_spec_file,
Kevin Linef321a52020-09-01 18:31:52 +080075 const CLIOutputFormat output_format,
76 bool pii);
Yong Hongcb45e082019-01-30 18:55:16 +080077
78 private:
79 friend class CLITest;
80
81 // Dependent classes.
82 std::unique_ptr<ProbeResultGetter> pr_getter_;
83 std::unique_ptr<HwVerificationSpecGetter> vp_getter_;
84 std::unique_ptr<Verifier> verifier_;
85
86 // Instance to the output stream, default to |std::cout|.
87 std::ostream* output_stream_;
Yong Hongcb45e082019-01-30 18:55:16 +080088};
89
90} // namespace hardware_verifier
91
92#endif // HARDWARE_VERIFIER_CLI_H_