xref: /aosp_15_r20/tools/netsim/scripts/tasks/run_test_task.py (revision cf78ab8cffb8fc9207af348f23af247fb04370a6)
1#!/usr/bin/env python3
2#
3# Copyright 2024 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the',  help="License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an',  help="AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17from pathlib import Path
18import platform
19
20from tasks.task import Task
21from utils import (AOSP_ROOT, run, rust_version)
22
23
24class RunTestTask(Task):
25
26  def __init__(self, args, env):
27    super().__init__("RunTest")
28    self.buildbot = args.buildbot
29    self.out = Path(args.out_dir)
30    self.env = env
31
32  def do_run(self):
33    # TODO(b/379745416): Support clippy for Mac and Windows
34    if platform.system() == "Linux":
35      # Set Clippy flags
36      clippy_flags = [
37          "-A clippy::disallowed_names",
38          "-A clippy::type-complexity",
39          "-A clippy::unnecessary-wraps",
40          "-A clippy::unusual-byte-groupings",
41          "-A clippy::upper-case-acronyms",
42          "-W clippy::undocumented_unsafe_blocks",
43          "-W clippy::cognitive-complexity",
44      ]
45      # Run cargo clippy
46      run(
47          [
48              AOSP_ROOT / "tools" / "netsim" / "scripts" / "cargo_clippy.sh",
49              str(self.out),
50              rust_version(),
51              " ".join(clippy_flags),
52          ],
53          self.env,
54          "clippy",
55      )
56
57    # Set script for cargo Test
58    if platform.system() == "Windows":
59      script = AOSP_ROOT / "tools" / "netsim" / "scripts" / "cargo_test.cmd"
60    else:
61      script = AOSP_ROOT / "tools" / "netsim" / "scripts" / "cargo_test.sh"
62
63    # Run cargo Test
64    for package in [
65        "hostapd-rs",
66        "libslirp-rs",
67        "http-proxy",
68        "netsim-common",
69        "netsim-daemon",
70        "netsim-packets",
71        "capture",
72    ]:
73      # TODO(b/379708365): Resolve netsim-daemon test for Mac & Windows
74      if package == "netsim-daemon" and platform.system() != "Linux":
75        continue
76      cmd = [script, package, str(self.out), rust_version()]
77      run(cmd, self.env, f"{package}_unit_tests")
78    return True
79