提交 ab4f7057 编写于 作者: J John Snow

qtest/ahci: export generate_pattern

Share the pattern function for ide and ahci test.
Signed-off-by: NJohn Snow <jsnow@redhat.com>
Message-id: 1441926555-19471-3-git-send-email-jsnow@redhat.com
上级 d7531638
...@@ -71,32 +71,6 @@ static void string_bswap16(uint16_t *s, size_t bytes) ...@@ -71,32 +71,6 @@ static void string_bswap16(uint16_t *s, size_t bytes)
} }
} }
static void generate_pattern(void *buffer, size_t len, size_t cycle_len)
{
int i, j;
unsigned char *tx = (unsigned char *)buffer;
unsigned char p;
size_t *sx;
/* Write an indicative pattern that varies and is unique per-cycle */
p = rand() % 256;
for (i = 0; i < len; i++) {
tx[i] = p++ % 256;
if (i % cycle_len == 0) {
p = rand() % 256;
}
}
/* force uniqueness by writing an id per-cycle */
for (i = 0; i < len / cycle_len; i++) {
j = i * cycle_len;
if (j + sizeof(*sx) <= len) {
sx = (size_t *)&tx[j];
*sx = i;
}
}
}
/** /**
* Verify that the transfer did not corrupt our state at all. * Verify that the transfer did not corrupt our state at all.
*/ */
......
...@@ -212,3 +212,29 @@ void prepare_blkdebug_script(const char *debug_fn, const char *event) ...@@ -212,3 +212,29 @@ void prepare_blkdebug_script(const char *debug_fn, const char *event)
ret = fclose(debug_file); ret = fclose(debug_file);
g_assert(ret == 0); g_assert(ret == 0);
} }
void generate_pattern(void *buffer, size_t len, size_t cycle_len)
{
int i, j;
unsigned char *tx = (unsigned char *)buffer;
unsigned char p;
size_t *sx;
/* Write an indicative pattern that varies and is unique per-cycle */
p = rand() % 256;
for (i = 0; i < len; i++) {
tx[i] = p++ % 256;
if (i % cycle_len == 0) {
p = rand() % 256;
}
}
/* force uniqueness by writing an id per-cycle */
for (i = 0; i < len / cycle_len; i++) {
j = i * cycle_len;
if (j + sizeof(*sx) <= len) {
sx = (size_t *)&tx[j];
*sx = i;
}
}
}
...@@ -24,6 +24,7 @@ void mkqcow2(const char *file, unsigned size_mb); ...@@ -24,6 +24,7 @@ void mkqcow2(const char *file, unsigned size_mb);
void set_context(QOSState *s); void set_context(QOSState *s);
void migrate(QOSState *from, QOSState *to, const char *uri); void migrate(QOSState *from, QOSState *to, const char *uri);
void prepare_blkdebug_script(const char *debug_fn, const char *event); void prepare_blkdebug_script(const char *debug_fn, const char *event);
void generate_pattern(void *buffer, size_t len, size_t cycle_len);
static inline uint64_t qmalloc(QOSState *q, size_t bytes) static inline uint64_t qmalloc(QOSState *q, size_t bytes)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册