check_gcp_environment_linux_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "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 "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  *
17  */
18 
20 
22 
23 #if GPR_LINUX
24 
25 #include <stdio.h>
26 #include <string.h>
27 
28 #include <grpc/support/alloc.h>
29 #include <grpc/support/log.h>
30 
32 
33 static bool check_bios_data_linux_test(const char* data) {
34  /* Create a file with contents data. */
35  char* filename = nullptr;
36  FILE* fp = gpr_tmpfile("check_gcp_environment_test", &filename);
37  GPR_ASSERT(filename != nullptr);
38  GPR_ASSERT(fp != nullptr);
39  GPR_ASSERT(fwrite(data, 1, strlen(data), fp) == strlen(data));
40  fclose(fp);
42  reinterpret_cast<const char*>(filename));
43  /* Cleanup. */
44  remove(filename);
46  return result;
47 }
48 
49 static void test_gcp_environment_check_success() {
50  /* Exact match. */
51  GPR_ASSERT(check_bios_data_linux_test("Google"));
52  GPR_ASSERT(check_bios_data_linux_test("Google Compute Engine"));
53  /* With leading and trailing whitespaces. */
54  GPR_ASSERT(check_bios_data_linux_test(" Google "));
55  GPR_ASSERT(check_bios_data_linux_test("Google "));
56  GPR_ASSERT(check_bios_data_linux_test(" Google"));
57  GPR_ASSERT(check_bios_data_linux_test(" Google Compute Engine "));
58  GPR_ASSERT(check_bios_data_linux_test("Google Compute Engine "));
59  GPR_ASSERT(check_bios_data_linux_test(" Google Compute Engine"));
60  /* With leading and trailing \t and \n. */
61  GPR_ASSERT(check_bios_data_linux_test("\t\tGoogle Compute Engine\t"));
62  GPR_ASSERT(check_bios_data_linux_test("Google Compute Engine\n"));
63  GPR_ASSERT(check_bios_data_linux_test("\n\n\tGoogle Compute Engine \n\t\t"));
64 }
65 
66 static void test_gcp_environment_check_failure() {
67  GPR_ASSERT(!check_bios_data_linux_test("non_existing-file"));
68  GPR_ASSERT(!check_bios_data_linux_test("Google-Chrome"));
69  GPR_ASSERT(!check_bios_data_linux_test("Amazon"));
70  GPR_ASSERT(!check_bios_data_linux_test("Google-Chrome\t\t"));
71  GPR_ASSERT(!check_bios_data_linux_test("Amazon"));
72  GPR_ASSERT(!check_bios_data_linux_test("\n"));
73 }
74 
75 int main(int /*argc*/, char** /*argv*/) {
76  /* Tests. */
77  test_gcp_environment_check_success();
78  test_gcp_environment_check_failure();
79  return 0;
80 }
81 
82 #else // GPR_LINUX
83 
84 int main(int /*argc*/, char** /*argv*/) { return 0; }
85 
86 #endif // GPR_LINUX
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
filename
const char * filename
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
log.h
grpc_core::internal::check_bios_data
bool check_bios_data(const char *bios_data)
string.h
main
int main(int, char **)
Definition: check_gcp_environment_linux_test.cc:84
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
gpr_tmpfile
FILE * gpr_tmpfile(const char *prefix, char **tmp_filename)
check_gcp_environment.h
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
tmpfile.h
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
benchmark.FILE
FILE
Definition: benchmark.py:21
grpc::fclose
fclose(creds_file)
alloc.h
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:44