ngraph.cpp 2.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// ----------------------------------------------------------------------------
// Copyright 2017 Nervana Systems Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------

#include <dlfcn.h>
16 17 18 19
#include <memory>
#include <sstream>
#include <string>
#include <vector>
20 21

#include "gtest/gtest.h"
22 23
#include "ngraph/log.hpp"
#include "ngraph/ngraph.hpp"
24 25 26 27 28 29

using namespace std;

TEST(NGraph, loadTest)
{
    // load the triangle library
30 31
    void* ngraphImplLib = dlopen("../src/libngraph.so", RTLD_LAZY);
    if (!ngraphImplLib)
32 33 34 35 36 37 38 39 40
    {
        std::cerr << "Cannot load library: " << dlerror() << '\n';
        ASSERT_FALSE(true);
    }

    // reset errors
    dlerror();

    // Get the symbols
41 42
    auto createPfn =
        reinterpret_cast<CreateNGraphObjPfn>(dlsym(ngraphImplLib, "create_ngraph_object"));
43 44
    ASSERT_FALSE(createPfn == nullptr);

45 46
    auto destroyPfn =
        reinterpret_cast<DestroyNGraphObjPfn>(dlsym(ngraphImplLib, "destroy_ngraph_object"));
47 48
    ASSERT_FALSE(destroyPfn == nullptr);

49
    NGraph* nGraphObj = createPfn();
50

Yixing Lao's avatar
Yixing Lao committed
51
    NGRAPH_INFO << "Call a method on the Object";
52
    ASSERT_EQ("NGraph Implementation Object", nGraphObj->get_name());
Yixing Lao's avatar
Yixing Lao committed
53
    NGRAPH_INFO << "Object Name: " << nGraphObj->get_name();
54 55 56 57

    // Add some parameters
    const vector<string> TEST_PARAMS = {"param-1", "param-2", "param-3"};

58
    nGraphObj->add_params(TEST_PARAMS);
59 60

    // Get the list of params
61 62
    auto& storedParams = nGraphObj->get_params();
    EXPECT_EQ(TEST_PARAMS.size(), storedParams.size());
63 64
    for (int i = 0; i < TEST_PARAMS.size(); i++)
    {
65
        EXPECT_EQ(TEST_PARAMS[i], storedParams[i]);
66 67
    }

Yixing Lao's avatar
Yixing Lao committed
68
    NGRAPH_INFO << "Destroy the NGraph Object";
69
    destroyPfn(nGraphObj);
70

71
    dlclose(ngraphImplLib);
72
}