Files
pytorch/caffe2/utils/proto_utils_test.cc
Junjie Bai f54ab540af Rename cuda_gpu_id to device_id in DeviceOption (#12456)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/12456

codemod with 'Yes to all'
codemod -d . --extensions h,cc,cpp,cu,py,proto,pbtxt,pb.txt,config cuda_gpu_id device_id

Overload TextFormat::ParseFromString to do string replace when parsing from protobuf format

Reviewed By: Yangqing

Differential Revision: D10240535

fbshipit-source-id: 5e6992bec961214be8dbe26f16f5794154a22b25
2018-10-09 15:54:04 -07:00

33 lines
917 B
C++

#include "caffe2/utils/proto_utils.h"
#include <gtest/gtest.h>
namespace caffe2 {
TEST(ProtoUtilsTest, IsSameDevice) {
DeviceOption a;
DeviceOption b;
EXPECT_TRUE(IsSameDevice(a, b));
a.set_node_name("my_node");
EXPECT_FALSE(IsSameDevice(a, b));
b.set_node_name("my_node");
EXPECT_TRUE(IsSameDevice(a, b));
b.set_device_id(2);
EXPECT_FALSE(IsSameDevice(a, b));
a.set_device_id(2);
EXPECT_TRUE(IsSameDevice(a, b));
a.set_device_type(DeviceTypeProto::PROTO_CUDA);
b.set_device_type(DeviceTypeProto::PROTO_CPU);
EXPECT_FALSE(IsSameDevice(a, b));
}
TEST(ProtoUtilsTest, SimpleReadWrite) {
string content("The quick brown fox jumps over the lazy dog.");
string name = std::tmpnam(nullptr);
EXPECT_TRUE(WriteStringToFile(content, name.c_str()));
string read_back;
EXPECT_TRUE(ReadStringFromFile(name.c_str(), &read_back));
EXPECT_EQ(content, read_back);
}
} // namespace caffe2