xref: /aosp_15_r20/external/federated-compute/fcp/tensorflow/tf_smoke_test.cc (revision 14675a029014e728ec732f129a32e299b2da0601)
1 /*
2  * Copyright 2019 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /**
18  * Runs a trivial TensorFlow session - just to know we can actually build it
19  * correctly.
20  */
21 
22 #include <stdint.h>
23 #include <vector>
24 
25 #include "gmock/gmock.h"
26 #include "gtest/gtest.h"
27 
28 #include "tensorflow/cc/client/client_session.h"
29 #include "tensorflow/cc/ops/standard_ops.h"
30 #include "tensorflow/core/framework/tensor.h"
31 #include "tensorflow/core/framework/tensor_testutil.h"
32 
33 namespace {
34 
35 using ::testing::Eq;
36 
37 using tensorflow::ClientSession;
38 using tensorflow::Scope;
39 using tensorflow::Tensor;
40 using tensorflow::TensorShape;
41 using tensorflow::test::AsTensor;
42 using tensorflow::test::ExpectTensorEqual;
43 using tensorflow::ops::Const;
44 using tensorflow::ops::Mul;
45 
TEST(TfSmokeTest,DoTrickyMath)46 TEST(TfSmokeTest, DoTrickyMath) {
47   Scope root = Scope::NewRootScope();
48   auto a = Const<int32_t>(root, { {1, 2}, {3, 4} });
49   auto b = Const<int32_t>(root, { {2} });
50   auto r = Mul(root.WithOpName("r"), a, b);
51   std::vector<Tensor> outputs;
52 
53   ClientSession session(root);
54   TF_CHECK_OK(session.Run({r}, &outputs));
55 
56   Tensor expected = AsTensor<int32_t>(
57       {2, 4, 6, 8},
58       TensorShape({2, 2}));
59 
60   EXPECT_THAT(outputs.size(), Eq(1));
61   ExpectTensorEqual<int32_t>(outputs[0], expected);
62 }
63 
64 }  // namespace
65