• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14require 'stringio'
15
16require_relative 'test_base'
17
18module Generator
19  class SingleTest < TestBase
20    def initialize(command, isa, definitions, predefined, skip_header)
21      super isa, command, definitions, predefined, skip_header
22
23      # command - YAML:
24      #   sig: Generator::TEST__SIG
25      #   check-type: Generator::CASE_CHECK_TYPE
26      #   cases: nil
27
28      @command = command
29      @isa = isa
30      @definitions = definitions
31      @predefined = predefined
32    end
33
34    def create_single_test
35      StringIO.open do |content|
36        write_test_initial_block content
37
38        test_run_options = @command[Generator::TEST_RUN_OPTIONS]
39        run_options = test_run_options
40        run_options = [] if run_options.nil?
41        ignore = @command[Generator::TEST_IGNORE] || false
42        bugids = @command[Generator::TEST_BUG_ID] || []
43        tags = @command[Generator::TEST_TAGS] || []
44        description = @command[Generator::TEST_DESCRIPTION] || ""
45        test_panda_options = @command[Generator::TEST_PANDA_OPTIONS] || ""
46
47        write_runner_options content, run_options, ignore, bugids, tags, description, test_panda_options
48
49        write_test_main_block content
50
51        content.puts @command[Generator::TEST_CODE_TEMPLATE]
52
53        case_check_type = @command.key?(Generator::TEST_CHECK_TYPE) ? @command[Generator::TEST_CHECK_TYPE] : Generator::TEMPLATE_CHECK_POSITIVE
54        # LOG.debug "case checking type is #{case_check_type}"
55        content.puts @predefined.definition case_check_type
56
57        write_test_main_wrapper_block content, run_options
58
59        content.string
60      end
61    end
62  end
63end
64