Skip to content

Commit

Permalink
Revert "DELETEME: more printf debugging"
Browse files Browse the repository at this point in the history
This reverts commit b3ff5fb.
  • Loading branch information
WillChilds-Klein committed Oct 11, 2023
1 parent 8e4112f commit a6f1b93
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions crypto/bio/bio_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ TEST(BIOTest, Printf) {
}

TEST(BIOTest, CloseFlags) {
printf("FOOBAR 0\n");
#if defined(OPENSSL_ANDROID)
// On Android, when running from an APK, |tmpfile| does not work. See
// b/36991167#comment8.
Expand All @@ -169,34 +168,26 @@ TEST(BIOTest, CloseFlags) {

const char *test_str = "test\ntest\ntest\n";

printf("FOOBAR 1\n");

// Assert that CRLF line endings get inserted on write and translated back out on
// read for text mode.
TempFILE text_bio_file(tmpfile(), fclose);
ASSERT_TRUE(text_bio_file);
printf("FOOBAR 2\n");
bssl::UniquePtr<BIO> text_bio(BIO_new_fp(text_bio_file.get(), BIO_NOCLOSE | BIO_FP_TEXT));
int bytes_written = BIO_write(text_bio.get(), test_str, strlen(test_str));
EXPECT_GE(bytes_written, 0);
printf("FOOBAR 3\n");
ASSERT_TRUE(BIO_flush(text_bio.get()));
ASSERT_EQ(0, BIO_seek(text_bio.get(), 0)); // 0 indicates success here
char contents[256];
printf("FOOBAR 4\n");
OPENSSL_memset(contents, 0, sizeof(contents));
int bytes_read = BIO_read(text_bio.get(), contents, sizeof(contents));
EXPECT_GE(bytes_read, bytes_written);
EXPECT_EQ(test_str, std::string(contents));

printf("FOOBAR 5\n");
// Windows should have translated '\n' to '\r\n' on write, so validate that
// by opening the file in raw binary mode (i.e. no BIO_FP_TEXT).
bssl::UniquePtr<BIO> text_bio_raw(BIO_new_fp(text_bio_file.get(), BIO_NOCLOSE));
ASSERT_EQ(0, BIO_seek(text_bio.get(), 0)); // 0 indicates success here
printf("FOOBAR 6\n");
OPENSSL_memset(contents, 0, sizeof(contents));
printf("FOOBAR 7\n");
bytes_read = BIO_read(text_bio_raw.get(), contents, sizeof(contents));
EXPECT_GT(bytes_read, 0);
#if defined(OPENSSL_WINDOWS)
Expand All @@ -205,18 +196,15 @@ TEST(BIOTest, CloseFlags) {
EXPECT_EQ(test_str, std::string(contents));
#endif

printf("FOOBAR 8\n");
// Assert that CRLF line endings don't get inserted on write for
// (default) binary mode.
TempFILE binary_bio_file(tmpfile(), fclose);
ASSERT_TRUE(binary_bio_file);
printf("FOOBAR 9\n");
bssl::UniquePtr<BIO> binary_bio(BIO_new_fp(binary_bio_file.get(), BIO_NOCLOSE));
bytes_written = BIO_write(binary_bio.get(), test_str, strlen(test_str));
EXPECT_EQ((int) strlen(test_str), bytes_written);
ASSERT_TRUE(BIO_flush(binary_bio.get()));
ASSERT_EQ(0, BIO_seek(binary_bio.get(), 0)); // 0 indicates success here
printf("FOOBAR 10\n");
OPENSSL_memset(contents, 0, sizeof(contents));
bytes_read = BIO_read(binary_bio.get(), contents, sizeof(contents));
EXPECT_GE(bytes_read, bytes_written);
Expand All @@ -228,12 +216,10 @@ TEST(BIOTest, CloseFlags) {
long pos;
char b1[256], b2[256];
binary_bio.reset(BIO_new_fp(binary_bio_file.get(), BIO_NOCLOSE));
printf("FOOBAR 11\n");
ASSERT_EQ(0, BIO_seek(binary_bio.get(), 0)); // 0 indicates success here
BIO_gets(binary_bio.get(), b1, sizeof(b1));
pos = BIO_tell(binary_bio.get());
BIO_gets(binary_bio.get(), b1, sizeof(b1));
printf("FOOBAR 12\n");
BIO_seek(binary_bio.get(), pos);
BIO_gets(binary_bio.get(), b2, sizeof(b2));
EXPECT_EQ(std::string(b1), std::string(b2));
Expand All @@ -242,33 +228,25 @@ TEST(BIOTest, CloseFlags) {
// (ftell will return < 0)
FILE *tmp = tmpfile();
ASSERT_TRUE(tmp);
printf("FOOBAR 13\n");
BIO *bio = BIO_new_fp(tmp, BIO_CLOSE);
EXPECT_EQ(0, BIO_tell(bio));
printf("FOOBAR 14\n");
// save off fd to avoid referencing |tmp| after free and angering valgrind
int tmp_fd = fileno(tmp);
EXPECT_LT(0, tmp_fd);
EXPECT_TRUE(BIO_free(bio));
printf("FOOBAR 15\n");
EXPECT_EQ(-1, lseek(tmp_fd, 0, SEEK_CUR));
EXPECT_EQ(errno, EBADF); // EBADF indicates taht |BIO_free| closed the file

printf("FOOBAR 16\n");
// Assert that BIO_NOCLOSE does not closethe underlying file on BIO free
tmp = tmpfile();
ASSERT_TRUE(tmp);
printf("FOOBAR 17\n");
bio = BIO_new_fp(tmp, BIO_NOCLOSE);
EXPECT_EQ(0, BIO_tell(bio));
EXPECT_TRUE(BIO_free(bio));
printf("FOOBAR 18\n");
EXPECT_TRUE(tmp);
EXPECT_EQ(0, ftell(tmp)); // 0 indicates file is still open
printf("FOOBAR 19\n");
EXPECT_LT(0, tmp_fd);
EXPECT_EQ(0, fclose(tmp)); // 0 indicates success for fclose
printf("FOOBAR 20\n");
}

TEST(BIOTest, ReadASN1) {
Expand Down

0 comments on commit a6f1b93

Please sign in to comment.