place_test.cc 901 字节
Newer Older
Y
Yi Wang 已提交
1 2
#include "majel/place.h"
#include <sstream>
L
liaogang 已提交
3
#include "gtest/gtest.h"
Y
Yi Wang 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

TEST(Place, Equality) {
  majel::CpuPlace cpu;
  majel::GpuPlace g0(0), g1(1), gg0(0);

  EXPECT_EQ(cpu, cpu);
  EXPECT_EQ(g0, g0);
  EXPECT_EQ(g1, g1);
  EXPECT_EQ(g0, gg0);

  EXPECT_NE(g0, g1);

  EXPECT_TRUE(majel::places_are_same_class(g0, gg0));
  EXPECT_FALSE(majel::places_are_same_class(g0, cpu));
}

TEST(Place, Default) {
L
liaogang 已提交
21 22 23
  EXPECT_TRUE(majel::is_gpu_place(majel::get_place()));
  EXPECT_TRUE(majel::is_gpu_place(majel::default_gpu()));
  EXPECT_TRUE(majel::is_cpu_place(majel::default_cpu()));
Y
Yi Wang 已提交
24 25

  majel::set_place(majel::CpuPlace());
L
liaogang 已提交
26
  EXPECT_TRUE(majel::is_cpu_place(majel::get_place()));
Y
Yi Wang 已提交
27 28 29 30 31 32 33 34 35
}

TEST(Place, Print) {
  {
    std::stringstream ss;
    ss << majel::GpuPlace(1);
    EXPECT_EQ("GpuPlace(1)", ss.str());
  }
  {
L
liaogang 已提交
36 37 38
    std::stringstream ss;
    ss << majel::CpuPlace();
    EXPECT_EQ("CpuPlace", ss.str());
Y
Yi Wang 已提交
39 40
  }
}