Debian Codegraph @

deps/curl/tests/azure.pm

raw
1 #***************************************************************************
2 # _ _ ____ _
3 # Project ___| | | | _ \| |
4 # / __| | | | |_) | |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 2020, Daniel Stenberg, <[email protected]>, et al.
9 # Copyright (C) 2020, Marc Hoersken, <[email protected]>
10 #
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at https://curl.haxx.se/docs/copyright.html.
14 #
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
18 #
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
21 #
22 ###########################################################################
23
24 use strict;
25 use warnings;
26
27 use POSIX qw(strftime);
28
29 sub azure_check_environment {
30 if(defined $ENV{'AZURE_ACCESS_TOKEN'} && $ENV{'AZURE_ACCESS_TOKEN'} &&
31 defined $ENV{'AGENT_JOBNAME'} && $ENV{'BUILD_BUILDID'} &&
32 defined $ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'} &&
33 defined $ENV{'SYSTEM_TEAMPROJECTID'}) {
34 return 1;
35 }
36 return 0;
37 }
38
39 sub azure_create_test_run {
40 my $azure_baseurl="$ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'}$ENV{'SYSTEM_TEAMPROJECTID'}";
41 my $azure_run=`curl --silent --noproxy "*" \\
42 --header "Authorization: Bearer $ENV{'AZURE_ACCESS_TOKEN'}" \\
43 --header "Content-Type: application/json" \\
44 --data "
45 {
46 'name': '$ENV{'AGENT_JOBNAME'}',
47 'automated': true,
48 'build': {'id': '$ENV{'BUILD_BUILDID'}'}
49 }
50 " \\
51 "$azure_baseurl/_apis/test/runs?api-version=5.0"`;
52 if($azure_run =~ /"id":(\d+)/) {
53 return $1;
54 }
55 return "";
56 }
57
58 sub azure_create_test_result {
59 my ($azure_run_id, $testnum, $testname)=@_;
60 $testname =~ s/\\/\\\\/g;
61 $testname =~ s/\'/\\\'/g;
62 $testname =~ s/\"/\\\"/g;
63 my $azure_baseurl="$ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'}$ENV{'SYSTEM_TEAMPROJECTID'}";
64 my $azure_result=`curl --silent --noproxy "*" \\
65 --header "Authorization: Bearer $ENV{'AZURE_ACCESS_TOKEN'}" \\
66 --header "Content-Type: application/json" \\
67 --data "
68 [
69 {
70 'build': {'id': '$ENV{'BUILD_BUILDID'}'},
71 'testCase': {'id': $testnum},
72 'testCaseTitle': '$testname',
73 'automatedTestName': 'curl.tests.$testnum',
74 'outcome': 'InProgress'
75 }
76 ]
77 " \\
78 "$azure_baseurl/_apis/test/runs/$azure_run_id/results?api-version=5.0"`;
79 if($azure_result =~ /\[\{"id":(\d+)/) {
80 return $1;
81 }
82 return "";
83 }
84
85 sub azure_update_test_result {
86 my ($azure_run_id, $azure_result_id, $testnum, $error, $start, $stop)=@_;
87 if(!defined $stop) {
88 $stop = $start;
89 }
90 my $azure_start = strftime "%Y-%m-%dT%H:%M:%SZ", gmtime $start;
91 my $azure_complete = strftime "%Y-%m-%dT%H:%M:%SZ", gmtime $stop;
92 my $azure_duration = sprintf("%.0f", ($stop-$start)*1000);
93 my $azure_outcome;
94 if($error == 2) {
95 $azure_outcome = 'Not applicable';
96 }
97 elsif($error < 0) {
98 $azure_outcome = 'Not executed';
99 }
100 elsif(!$error) {
101 $azure_outcome = 'Passed';
102 }
103 else {
104 $azure_outcome = 'Failed';
105 }
106 my $azure_baseurl="$ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'}$ENV{'SYSTEM_TEAMPROJECTID'}";
107 my $azure_result=`curl --silent --noproxy "*" --request PATCH \\
108 --header "Authorization: Bearer $ENV{'AZURE_ACCESS_TOKEN'}" \\
109 --header "Content-Type: application/json" \\
110 --data "
111 [
112 {
113 'id': $azure_result_id,
114 'outcome': '$azure_outcome',
115 'startedDate': '$azure_start',
116 'completedDate': '$azure_complete',
117 'durationInMs': $azure_duration
118 }
119 ]
120 " \\
121 "$azure_baseurl/_apis/test/runs/$azure_run_id/results?api-version=5.0"`;
122 if($azure_result =~ /\[\{"id":(\d+)/) {
123 return $1;
124 }
125 return "";
126 }
127
128 sub azure_update_test_run {
129 my ($azure_run_id)=@_;
130 my $azure_baseurl="$ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'}$ENV{'SYSTEM_TEAMPROJECTID'}";
131 my $azure_run=`curl --silent --noproxy "*" --request PATCH \\
132 --header "Authorization: Bearer $ENV{'AZURE_ACCESS_TOKEN'}" \\
133 --header "Content-Type: application/json" \\
134 --data "
135 {
136 'state': 'Completed'
137 }
138 " \\
139 "$azure_baseurl/_apis/test/runs/$azure_run_id?api-version=5.0"`;
140 if($azure_run =~ /"id":(\d+)/) {
141 return $1;
142 }
143 return "";
144 }
145
146 1;