Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 758e9334 authored by Chris Manton's avatar Chris Manton
Browse files

mockcify: ==> 0.7.0 Comment out unused variables

Bug: 307434706
Test: m .

Change-Id: Ib99dde5423c7699be2b06c5ca1d2290868597438
parent 2c9626ee
Loading
Loading
Loading
Loading
+0 −0

Empty file added.

+9 −2
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ use File::Basename;

## mockcify version
##
## 0.7.0 Comment out unused mock variables
##
## 0.6.3 Streamline inclusion for headers and source
##
## 0.6.2 Add tBTA_STATUS default value, Cpp type failure log
@@ -42,11 +44,15 @@ use File::Basename;
##
## 0.2.0 First version
##
my $VERSION = "0.6.3";
my $VERSION = "0.7.0";

use diagnostics;
use strict;
use warnings;

use lib "$ENV{ANDROID_BUILD_TOP}/packages/modules/Bluetooth/system/test/tool";
require 'mockcify_util.pl';

my $YEAR = "2023";
my $TOKEN = "MOCKCIFY_TOKEN";
my $MOCKCIFY_BRACKET_GROUP = "MOCKCIFY_BRACKET_GROUP";
@@ -695,6 +701,7 @@ namespace $namespace {
EOF
  foreach my $name (sort @function_names) {
      my $input_params = $function_params{$name};
      my $vars_commented_out_input_params = comment_out_input_vars($input_params);
      my $return_type = $function_return_types{$name};
      my @param_names = $function_param_names{$name};
      assert($return_type ne '');
@@ -714,7 +721,7 @@ EOF
           print $FH "$return_definition\n";
       }
print $FH <<EOF;
    std::function<$return_type($input_params)> body{[]($input_params){$return_statement}};
    std::function<$return_type($input_params)> body{[]($vars_commented_out_input_params){$return_statement}};
    $return_type operator()($input_params) { ${return_keyword} body($function_param_names);};
};
extern struct $name $name;
+21 −17
Original line number Diff line number Diff line
@@ -14,22 +14,26 @@
## See the License for the specific language governing permissions and
## limitations under the License.

my $MOCKCIFY="./test/tool/mockcify.pl";
package Mockcify;

my @tests=(
    "osi/src/allocator.cc",
    "osi/src/list.cc",
    "osi/src/mutex.cc",
);
use diagnostics;
use strict;
use warnings;

print;
foreach (@tests) {
    print(STDOUT "\33[2K\r$_\r");
    my $cmd = "$MOCKCIFY TEST < $_";
    my $rc = system("$cmd > /dev/null 2&>1");
    if ($rc != 0) {
        print(STDERR "\nFAILED \'$_\' cmd:\'$cmd\'\n");
        exit 1;
    }
}
print(STDERR "\33[2K\rPASSED\n");
use lib "$ENV{ANDROID_BUILD_TOP}/packages/modules/Bluetooth/system/test/tool";
require 'mockcify_util.pl';

printf("MOCKCIFY unit test\n");

"void" eq comment_out_input_vars("void")
    || die("FAIL file:",  __FILE__, " line:", __LINE__, "\n");
"one /* two */" eq comment_out_input_vars("one two")
    || die("FAIL file:",  __FILE__, " line:", __LINE__, "\n");
"one /* two */, three /* four */, five /* six */" eq comment_out_input_vars("one two, three four, five six")
    || die("FAIL file:",  __FILE__, " line:", __LINE__, "\n");
"std::string /* s */, tSOME_STRUCT /* struct */" eq comment_out_input_vars("std::string   s  ,   tSOME_STRUCT  struct")
    || die("FAIL file:",  __FILE__, " line:", __LINE__, "\n");
"const std::string& /* s */, tSOME_STRUCT /* struct */" eq comment_out_input_vars("   const   std::string&   s  ,   tSOME_STRUCT  struct")
    || die("FAIL file:",  __FILE__, " line:", __LINE__, "\n");

printf("SUCCESS\n");
+47 −0
Original line number Diff line number Diff line
##
## Copyright 2023 The Android Open Source Project
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##      http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

use diagnostics;
use strict;
use warnings;

##
## Take a string of parameters in and return the parameter name commented out
##
## e.g.
## int a, char b, std::string c => int /* a */, char /* b */, std::string /* c */
##
sub comment_out_input_vars {
    my $input_param_string = shift @_;
    my @return_param_string;
    my @params = split /,/, $input_param_string;
    foreach (@params) {
        ## Trim leading and trailing space
        s/^\s+|\s+$//g;
        ## Reduce multiple internal spaces to single space
        s/\s\+/ /g;
        my @w = split /\s+/, $_;
        my $s;
        if ($#w != 0) {
            chomp($w[$#w]);
            $w[$#w] = "/* $w[$#w] */";
        }
        $s .= join " ", @w;
        push(@return_param_string, $s);
      }
      return join(', ', @return_param_string);
}

1;