| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <errno.h> | 5 #include <errno.h> |
| 6 #include <sys/file.h> | 6 #include <sys/file.h> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // want to test the ability to deal with a file containing more than one | 80 // want to test the ability to deal with a file containing more than one |
| 81 // message. | 81 // message. |
| 82 for (i = 0; i < nhist; i++) { | 82 for (i = 0; i < nhist; i++) { |
| 83 SendMessage(path, "histogram", histogram_data[i]); | 83 SendMessage(path, "histogram", histogram_data[i]); |
| 84 if (i % 3 == 2) { | 84 if (i % 3 == 2) { |
| 85 external_metrics->CollectEvents(); | 85 external_metrics->CollectEvents(); |
| 86 CheckMessage("histogram", histogram_data[i], i + 1); | 86 CheckMessage("histogram", histogram_data[i], i + 1); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Sends a crash message. |
| 91 int expect_count = nhist; |
| 92 SendMessage(path, "crash", "user"); |
| 93 external_metrics->CollectEvents(); |
| 94 CheckMessage("crash", "user", ++expect_count); |
| 95 |
| 90 // Sends a message that's too large. | 96 // Sends a message that's too large. |
| 91 char b[MAXLENGTH + 100]; | 97 char b[MAXLENGTH + 100]; |
| 92 for (i = 0; i < MAXLENGTH + 99; i++) { | 98 for (i = 0; i < MAXLENGTH + 99; i++) { |
| 93 b[i] = 'x'; | 99 b[i] = 'x'; |
| 94 } | 100 } |
| 95 b[i] = '\0'; | 101 b[i] = '\0'; |
| 96 SendMessage(path, b, "yyy"); | 102 SendMessage(path, b, "yyy"); |
| 103 // Expect logged errors about bad message size. |
| 97 external_metrics->CollectEvents(); | 104 external_metrics->CollectEvents(); |
| 98 EXPECT_EQ(received_count, nhist); | 105 EXPECT_EQ(expect_count, received_count); |
| 99 | 106 |
| 100 // Sends a malformed message (first string is not null-terminated). | 107 // Sends a malformed message (first string is not null-terminated). |
| 101 i = 100 + sizeof(i); | 108 i = 100 + sizeof(i); |
| 102 int fd = open(path, O_CREAT | O_WRONLY, 0666); | 109 int fd = open(path, O_CREAT | O_WRONLY, 0666); |
| 103 EXPECT_GT(fd, 0); | 110 EXPECT_GT(fd, 0); |
| 104 EXPECT_EQ(write(fd, &i, sizeof(i)), static_cast<int>(sizeof(i))); | 111 EXPECT_EQ(static_cast<int>(sizeof(i)), write(fd, &i, sizeof(i))); |
| 105 EXPECT_EQ(write(fd, b, i), i); | 112 EXPECT_EQ(i, write(fd, b, i)); |
| 106 EXPECT_EQ(close(fd), 0); | 113 EXPECT_EQ(0, close(fd)); |
| 107 | 114 |
| 108 external_metrics->CollectEvents(); | 115 external_metrics->CollectEvents(); |
| 109 EXPECT_EQ(received_count, nhist); | 116 EXPECT_EQ(expect_count, received_count); |
| 110 | 117 |
| 111 // Sends a malformed message (second string is not null-terminated). | 118 // Sends a malformed message (second string is not null-terminated). |
| 112 b[50] = '\0'; | 119 b[50] = '\0'; |
| 113 fd = open(path, O_CREAT | O_WRONLY, 0666); | 120 fd = open(path, O_CREAT | O_WRONLY, 0666); |
| 114 EXPECT_GT(fd, 0); | 121 EXPECT_GT(fd, 0); |
| 115 EXPECT_EQ(write(fd, &i, sizeof(i)), static_cast<int>(sizeof(i))); | 122 EXPECT_EQ(static_cast<int>(sizeof(i)), write(fd, &i, sizeof(i))); |
| 116 EXPECT_EQ(write(fd, b, i), i); | 123 EXPECT_EQ(i, write(fd, b, i)); |
| 117 EXPECT_EQ(close(fd), 0); | 124 EXPECT_EQ(0, close(fd)); |
| 118 | 125 |
| 119 external_metrics->CollectEvents(); | 126 external_metrics->CollectEvents(); |
| 120 EXPECT_EQ(received_count, nhist); | 127 EXPECT_EQ(expect_count, received_count); |
| 121 | 128 |
| 122 // Checks that we survive when file doesn't exist. | 129 // Checks that we survive when file doesn't exist. |
| 123 EXPECT_EQ(unlink(path), 0); | 130 EXPECT_EQ(0, unlink(path)); |
| 124 external_metrics->CollectEvents(); | 131 external_metrics->CollectEvents(); |
| 125 EXPECT_EQ(received_count, nhist); | 132 EXPECT_EQ(expect_count, received_count); |
| 126 } | 133 } |
| 127 | 134 |
| 128 } // namespace chromeos | 135 } // namespace chromeos |
| OLD | NEW |