• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <math.h>
3 
4 #include "math_data_test.h"
5 #include "math_test_data/fmaf_data.h"
6 #include "math_test_data/fma_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathFmaTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: fma_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the fma interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathFmaTest, fma_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_fmaData) / sizeof(DataDouble4); i++) {
24         bool testResult = DoubleUlpCmp(g_fmaData[i].expected, fma(g_fmaData[i].input1, g_fmaData[i].input2,
25             g_fmaData[i].input3), 1);
26         EXPECT_TRUE(testResult);
27     }
28 }
29 
30 /**
31  * @tc.name: fma_002
32  * @tc.desc: When the parameter of fma is valid, test the return value of the function.
33  * @tc.type: FUNC
34  */
35 HWTEST_F(MathFmaTest, fma_002, TestSize.Level1)
36 {
37     EXPECT_DOUBLE_EQ(17.0, fma(3.0, 4.0, 5.0));
38 }
39 
40 /**
41  * @tc.name: fmaf_001
42  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the fmaf interface.
43  * @tc.type: FUNC
44  */
45 HWTEST_F(MathFmaTest, fmaf_001, TestSize.Level1)
46 {
47     fesetenv(FE_DFL_ENV);
48     for (int i = 0; i < sizeof(g_fmafData) / sizeof(DataFloat4); i++) {
49         bool testResult = FloatUlpCmp(g_fmafData[i].expected, fmaf(g_fmafData[i].input1, g_fmafData[i].input2,
50             g_fmafData[i].input3), 1);
51         EXPECT_TRUE(testResult);
52     }
53 }
54 
55 /**
56  * @tc.name: fmaf_002
57  * @tc.desc: When the parameter of fmaf is valid, test the return value of the function.
58  * @tc.type: FUNC
59  */
60 HWTEST_F(MathFmaTest, fmaf_002, TestSize.Level1)
61 {
62     EXPECT_FLOAT_EQ(17.0f, fmaf(3.0f, 4.0f, 5.0f));
63 }
64 
65 /**
66  * @tc.name: fmal_001
67  * @tc.desc: When the parameter of fmal is valid, test the return value of the function.
68  * @tc.type: FUNC
69  */
70 HWTEST_F(MathFmaTest, fmal_001, TestSize.Level1)
71 {
72     EXPECT_DOUBLE_EQ(17.0L, fmal(3.0L, 4.0L, 5.0L));
73 }