xref: /aosp_15_r20/external/curl/tests/appveyor.pm (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker#***************************************************************************
2*6236dae4SAndroid Build Coastguard Worker#                                  _   _ ____  _
3*6236dae4SAndroid Build Coastguard Worker#  Project                     ___| | | |  _ \| |
4*6236dae4SAndroid Build Coastguard Worker#                             / __| | | | |_) | |
5*6236dae4SAndroid Build Coastguard Worker#                            | (__| |_| |  _ <| |___
6*6236dae4SAndroid Build Coastguard Worker#                             \___|\___/|_| \_\_____|
7*6236dae4SAndroid Build Coastguard Worker#
8*6236dae4SAndroid Build Coastguard Worker# Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9*6236dae4SAndroid Build Coastguard Worker# Copyright (C) Marc Hoersken, <[email protected]>
10*6236dae4SAndroid Build Coastguard Worker#
11*6236dae4SAndroid Build Coastguard Worker# This software is licensed as described in the file COPYING, which
12*6236dae4SAndroid Build Coastguard Worker# you should have received as part of this distribution. The terms
13*6236dae4SAndroid Build Coastguard Worker# are also available at https://curl.se/docs/copyright.html.
14*6236dae4SAndroid Build Coastguard Worker#
15*6236dae4SAndroid Build Coastguard Worker# You may opt to use, copy, modify, merge, publish, distribute and/or sell
16*6236dae4SAndroid Build Coastguard Worker# copies of the Software, and permit persons to whom the Software is
17*6236dae4SAndroid Build Coastguard Worker# furnished to do so, under the terms of the COPYING file.
18*6236dae4SAndroid Build Coastguard Worker#
19*6236dae4SAndroid Build Coastguard Worker# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20*6236dae4SAndroid Build Coastguard Worker# KIND, either express or implied.
21*6236dae4SAndroid Build Coastguard Worker#
22*6236dae4SAndroid Build Coastguard Worker# SPDX-License-Identifier: curl
23*6236dae4SAndroid Build Coastguard Worker#
24*6236dae4SAndroid Build Coastguard Worker###########################################################################
25*6236dae4SAndroid Build Coastguard Worker
26*6236dae4SAndroid Build Coastguard Workerpackage appveyor;
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard Workeruse strict;
29*6236dae4SAndroid Build Coastguard Workeruse warnings;
30*6236dae4SAndroid Build Coastguard Worker
31*6236dae4SAndroid Build Coastguard WorkerBEGIN {
32*6236dae4SAndroid Build Coastguard Worker    use base qw(Exporter);
33*6236dae4SAndroid Build Coastguard Worker
34*6236dae4SAndroid Build Coastguard Worker    our @EXPORT = qw(
35*6236dae4SAndroid Build Coastguard Worker      appveyor_check_environment
36*6236dae4SAndroid Build Coastguard Worker      appveyor_create_test_result
37*6236dae4SAndroid Build Coastguard Worker      appveyor_update_test_result
38*6236dae4SAndroid Build Coastguard Worker    );
39*6236dae4SAndroid Build Coastguard Worker}
40*6236dae4SAndroid Build Coastguard Worker
41*6236dae4SAndroid Build Coastguard Worker
42*6236dae4SAndroid Build Coastguard Workermy %APPVEYOR_TEST_NAMES;  # JSON and shell-quoted test names by test number
43*6236dae4SAndroid Build Coastguard Worker
44*6236dae4SAndroid Build Coastguard Workersub appveyor_check_environment {
45*6236dae4SAndroid Build Coastguard Worker    if(defined $ENV{'APPVEYOR_API_URL'} && $ENV{'APPVEYOR_API_URL'}) {
46*6236dae4SAndroid Build Coastguard Worker        return 1;
47*6236dae4SAndroid Build Coastguard Worker    }
48*6236dae4SAndroid Build Coastguard Worker    return 0;
49*6236dae4SAndroid Build Coastguard Worker}
50*6236dae4SAndroid Build Coastguard Worker
51*6236dae4SAndroid Build Coastguard Workersub appveyor_create_test_result {
52*6236dae4SAndroid Build Coastguard Worker    my ($curl, $testnum, $testname)=@_;
53*6236dae4SAndroid Build Coastguard Worker    $testname =~ s/\\/\\\\/g;
54*6236dae4SAndroid Build Coastguard Worker    $testname =~ s/\"/\\\"/g;
55*6236dae4SAndroid Build Coastguard Worker    $testname =~ s/\'/'"'"'/g;
56*6236dae4SAndroid Build Coastguard Worker    my $appveyor_baseurl="$ENV{'APPVEYOR_API_URL'}";
57*6236dae4SAndroid Build Coastguard Worker    my $appveyor_result=`$curl --silent --noproxy '*' \\
58*6236dae4SAndroid Build Coastguard Worker    --header 'Content-Type: application/json' \\
59*6236dae4SAndroid Build Coastguard Worker    --data '
60*6236dae4SAndroid Build Coastguard Worker        {
61*6236dae4SAndroid Build Coastguard Worker            "testName": "$testname",
62*6236dae4SAndroid Build Coastguard Worker            "testFramework": "runtests.pl",
63*6236dae4SAndroid Build Coastguard Worker            "fileName": "tests/data/test$testnum",
64*6236dae4SAndroid Build Coastguard Worker            "outcome": "Running"
65*6236dae4SAndroid Build Coastguard Worker        }
66*6236dae4SAndroid Build Coastguard Worker    ' \\
67*6236dae4SAndroid Build Coastguard Worker    '$appveyor_baseurl/api/tests'`;
68*6236dae4SAndroid Build Coastguard Worker    print "AppVeyor API result: $appveyor_result\n" if ($appveyor_result);
69*6236dae4SAndroid Build Coastguard Worker    $APPVEYOR_TEST_NAMES{$testnum}=$testname;
70*6236dae4SAndroid Build Coastguard Worker}
71*6236dae4SAndroid Build Coastguard Worker
72*6236dae4SAndroid Build Coastguard Workersub appveyor_update_test_result {
73*6236dae4SAndroid Build Coastguard Worker    my ($curl, $testnum, $error, $start, $stop)=@_;
74*6236dae4SAndroid Build Coastguard Worker    my $testname=$APPVEYOR_TEST_NAMES{$testnum};
75*6236dae4SAndroid Build Coastguard Worker    if(!defined $testname) {
76*6236dae4SAndroid Build Coastguard Worker        return;
77*6236dae4SAndroid Build Coastguard Worker    }
78*6236dae4SAndroid Build Coastguard Worker    if(!defined $stop) {
79*6236dae4SAndroid Build Coastguard Worker        $stop = $start;
80*6236dae4SAndroid Build Coastguard Worker    }
81*6236dae4SAndroid Build Coastguard Worker    my $appveyor_duration = sprintf("%.0f", ($stop-$start)*1000);
82*6236dae4SAndroid Build Coastguard Worker    my $appveyor_outcome;
83*6236dae4SAndroid Build Coastguard Worker    my $appveyor_category;
84*6236dae4SAndroid Build Coastguard Worker    if($error == 2) {
85*6236dae4SAndroid Build Coastguard Worker        $appveyor_outcome = 'Ignored';
86*6236dae4SAndroid Build Coastguard Worker        $appveyor_category = 'Error';
87*6236dae4SAndroid Build Coastguard Worker    }
88*6236dae4SAndroid Build Coastguard Worker    elsif($error < 0) {
89*6236dae4SAndroid Build Coastguard Worker        $appveyor_outcome = 'NotRunnable';
90*6236dae4SAndroid Build Coastguard Worker        $appveyor_category = 'Warning';
91*6236dae4SAndroid Build Coastguard Worker    }
92*6236dae4SAndroid Build Coastguard Worker    elsif(!$error) {
93*6236dae4SAndroid Build Coastguard Worker        $appveyor_outcome = 'Passed';
94*6236dae4SAndroid Build Coastguard Worker        $appveyor_category = 'Information';
95*6236dae4SAndroid Build Coastguard Worker    }
96*6236dae4SAndroid Build Coastguard Worker    else {
97*6236dae4SAndroid Build Coastguard Worker        $appveyor_outcome = 'Failed';
98*6236dae4SAndroid Build Coastguard Worker        $appveyor_category = 'Error';
99*6236dae4SAndroid Build Coastguard Worker    }
100*6236dae4SAndroid Build Coastguard Worker    my $appveyor_baseurl="$ENV{'APPVEYOR_API_URL'}";
101*6236dae4SAndroid Build Coastguard Worker    my $appveyor_result=`$curl --silent --noproxy '*' --request PUT \\
102*6236dae4SAndroid Build Coastguard Worker    --header 'Content-Type: application/json' \\
103*6236dae4SAndroid Build Coastguard Worker    --data '
104*6236dae4SAndroid Build Coastguard Worker        {
105*6236dae4SAndroid Build Coastguard Worker            "testName": "$testname",
106*6236dae4SAndroid Build Coastguard Worker            "testFramework": "runtests.pl",
107*6236dae4SAndroid Build Coastguard Worker            "fileName": "tests/data/test$testnum",
108*6236dae4SAndroid Build Coastguard Worker            "outcome": "$appveyor_outcome",
109*6236dae4SAndroid Build Coastguard Worker            "durationMilliseconds": $appveyor_duration,
110*6236dae4SAndroid Build Coastguard Worker            "ErrorMessage": "Test $testnum $appveyor_outcome"
111*6236dae4SAndroid Build Coastguard Worker        }
112*6236dae4SAndroid Build Coastguard Worker    ' \\
113*6236dae4SAndroid Build Coastguard Worker    '$appveyor_baseurl/api/tests'`;
114*6236dae4SAndroid Build Coastguard Worker    print "AppVeyor API result: $appveyor_result\n" if ($appveyor_result);
115*6236dae4SAndroid Build Coastguard Worker    if($appveyor_category eq 'Error') {
116*6236dae4SAndroid Build Coastguard Worker        $appveyor_result=`$curl --silent --noproxy '*' \\
117*6236dae4SAndroid Build Coastguard Worker        --header 'Content-Type: application/json' \\
118*6236dae4SAndroid Build Coastguard Worker        --data '
119*6236dae4SAndroid Build Coastguard Worker            {
120*6236dae4SAndroid Build Coastguard Worker                "message": "$appveyor_outcome: $testname",
121*6236dae4SAndroid Build Coastguard Worker                "category": "$appveyor_category",
122*6236dae4SAndroid Build Coastguard Worker                "details": "Test $testnum $appveyor_outcome"
123*6236dae4SAndroid Build Coastguard Worker            }
124*6236dae4SAndroid Build Coastguard Worker        ' \\
125*6236dae4SAndroid Build Coastguard Worker        '$appveyor_baseurl/api/build/messages'`;
126*6236dae4SAndroid Build Coastguard Worker        print "AppVeyor API result: $appveyor_result\n" if ($appveyor_result);
127*6236dae4SAndroid Build Coastguard Worker    }
128*6236dae4SAndroid Build Coastguard Worker}
129*6236dae4SAndroid Build Coastguard Worker
130*6236dae4SAndroid Build Coastguard Worker1;
131